Use lobstr instead of pryr
This commit is contained in:
parent
c5291a7a86
commit
3e3faea9cb
|
@ -18,12 +18,12 @@ Imports:
|
||||||
janitor,
|
janitor,
|
||||||
Lahman,
|
Lahman,
|
||||||
leaflet,
|
leaflet,
|
||||||
|
lobstr,
|
||||||
maps,
|
maps,
|
||||||
microbenchmark,
|
microbenchmark,
|
||||||
nycflights13,
|
nycflights13,
|
||||||
openxlsx,
|
openxlsx,
|
||||||
palmerpenguins,
|
palmerpenguins,
|
||||||
pryr,
|
|
||||||
readxl,
|
readxl,
|
||||||
stringr,
|
stringr,
|
||||||
tidyverse,
|
tidyverse,
|
||||||
|
|
|
@ -137,18 +137,18 @@ You've already learned a lot about working with strings in [strings].
|
||||||
Here I wanted to mention one important feature of the underlying string implementation: R uses a global string pool.
|
Here I wanted to mention one important feature of the underlying string implementation: R uses a global string pool.
|
||||||
This means that each unique string is only stored in memory once, and every use of the string points to that representation.
|
This means that each unique string is only stored in memory once, and every use of the string points to that representation.
|
||||||
This reduces the amount of memory needed by duplicated strings.
|
This reduces the amount of memory needed by duplicated strings.
|
||||||
You can see this behaviour in practice with `pryr::object_size()`:
|
You can see this behaviour in practice with `lobstr::obj_size()`:
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
x <- "This is a reasonably long string."
|
x <- "This is a reasonably long string."
|
||||||
pryr::object_size(x)
|
lobstr::obj_size(x)
|
||||||
|
|
||||||
y <- rep(x, 1000)
|
y <- rep(x, 1000)
|
||||||
pryr::object_size(y)
|
lobstr::obj_size(y)
|
||||||
```
|
```
|
||||||
|
|
||||||
`y` doesn't take up 1,000x as much memory as `x`, because each element of `y` is just a pointer to that same string.
|
`y` doesn't take up 1,000x as much memory as `x`, because each element of `y` is just a pointer to that same string.
|
||||||
A pointer is 8 bytes, so 1000 pointers to a 152 B string is 8 \* 1000 + 152 = 8.14 kB.
|
A pointer is 8 bytes, so 1000 pointers to a 152 B string is 8 \* 1000 + 152 = 8,144 B.
|
||||||
|
|
||||||
### Missing values {#missing-values-vectors}
|
### Missing values {#missing-values-vectors}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue