Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imported object environment size increases when loading other modules #366

Open
mjakubczak opened this issue Jun 12, 2024 · 2 comments
Open

Comments

@mjakubczak
Copy link

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

@klmr
Copy link
Owner

klmr commented Jun 12, 2024

I cannot reproduce this: when I execute the code, the object sizes stay constant. This is true across multiple systems and versions of R.

Here’s the output I get when running the exact same commands as you:

> box::use(./m1[foo])

> pryr::object_size(foo)
28.62 kB

> box::use(./m2[bar])

> pryr::object_size(foo)
28.62 kB

> pryr::object_size(bar)
50.69 kB

> box::use(./m3[baz])

> pryr::object_size(foo)
28.62 kB

> pryr::object_size(bar)
50.69 kB

> pryr::object_size(baz)
28.19 kB

@mjakubczak
Copy link
Author

@klmr Thank you for the quick answer. I've determined that renv could be involved in this issue - please check this repo for a minimal reprex: https://github.com/mjakubczak/boxtest/

tl;dr:
with renv:

> pryr::object_size(foo)
203.02 kB
> pryr::object_size(bar)
203.02 kB
> pryr::object_size(baz)
203.02 kB

without renv:

> pryr::object_size(foo)
24.75 kB
> pryr::object_size(bar)
22.64 kB
> pryr::object_size(baz)
23.44 kB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants