Skip to content

Latest commit

 

History

History
63 lines (51 loc) · 1.59 KB

ObjectSize.md

File metadata and controls

63 lines (51 loc) · 1.59 KB

Many of the object size estimation methods in R have different opinions as to whether they count environments, which can be a very large component of objects.

Some related articles:

build1 <- function() {
  x <- 1:1e+7 # this variable will be in f's closure
  f = function(i) {
    print(x[[i]])
  }
  print(paste(
    "serialize size in construction environment",
    length(serialize(f, NULL))
  ))
  print(paste(
    "pryr::object_size in construction environment",
    pryr::object_size(f)
  ))
  print(paste(
    "utils::object.size in construction environment",
    utils::object.size(f)
  ))
  f
}

f <- build1()
## [1] "serialize size in construction environment 40014302"
## [1] "pryr::object_size in construction environment 19880"
## [1] "utils::object.size in construction environment 4608"
print(paste(
  "serialize size in global environment",
  length(serialize(f, NULL))
))
## [1] "serialize size in global environment 40014302"
print(paste(
  "pryr::object_size in global environment",
  pryr::object_size(f)
))
## [1] "pryr::object_size in global environment 40020144"
print(paste(
  "utils::object.size in global environment",
  utils::object.size(f)
))
## [1] "utils::object.size in global environment 4608"

(Filed as pryr issue 37, and closed.)