Skip to content

Imported object environment size increases when loading other modules #366

@mjakubczak

Description

@mjakubczak

Error description

Object size increases when importing multiple modules. This is really strange, because nothing happens to the object environment. In this example the size increases from 435kB to 26MB (!) just when loading 2nd module. Looks like all imported objects share the same resources, because finally all of them have the same accumulated size.

m1.R

box::use(dplyr[mutate])

#' @export
foo <- function(x){
  x |> mutate(m1 = 1)
}

dummy <- 2

m2.R

box::use(ggplot2[ggplot, aes, geom_point])

#' @export
bar <- function(x){
  ggplot(x, aes(Sepal.Width, Petal.length)) + geom_point()
}

m3.R

box::use(tidyr[drop_na])

#' @export
baz <- function(x){
  drop_na(x)
}

some_var <- "hi"

console output

> box::use(. / m1[foo])
> 
> pryr::object_size(foo)
435.83 kB
> 
> box::use(. / m2[bar])
> 
> pryr::object_size(foo) # the object size increases
25.84 MB
> pryr::object_size(bar)
25.84 MB
> 
> ls(environment(foo)) # environments look as expected
[1] "dummy" "foo"  
> ls(environment(bar))
[1] "bar"
> 
> box::use(. / m3[baz])
> 
> pryr::object_size(foo) # all objects have the same size
25.96 MB
> pryr::object_size(bar)
25.96 MB
> pryr::object_size(baz)
25.96 MB

R version

> R.version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          4                           
minor          1.1                         
year           2021                        
month          08                          
day            10                          
svn rev        80725                       
language       R                           
version.string R version 4.1.1 (2021-08-10)
nickname       Kick Things

‘box’ version

1.2.0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions