[R] Issue with gc() on Ubuntu 20.04

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Sun Aug 27 22:02:23 CEST 2023


On Sun, 27 Aug 2023 19:54:23 +0100
John Logsdon <j.logsdon using quantex-research.com> wrote:

> Not so although it did lower the gc() time to 95.84%.
> 
> This was on a 16 core Threadripper 1950X box so I was intending to
> use library parallel but I tried it on my lowly windows box that is
> years old and got it down to 88.07%.

Does the Windows box have the same version of R on it?

> The only thing I can think of is that there are quite a lot of cases 
> where a function is generated on the fly as in:
> 
> eval(parse(t=paste("dprob <- 
> function(x,l,s){",dist.functions[2,][dist.functions[1,]==distn],"(x,l,s)}",sep="")))

This isn't very idiomatic. If you need dprob to call the function named
in dist.functions[2,][dist.functions[1,]==distn], wouldn't it be easier
for R to assign that function straight to dprob?

dprob <- get(dist.functions[2,][dist.functions[1,]==distn])

This way, you avoid the need to parse the code, which is typically not
the fastest part of a programming language.

(Generally in R and other programming languages with recursive data
structures, storing variable names in other variables is not very
efficient. Why not put functions directly into a list?)

Rprof() samples the whole call stack. Can you find out which functions
result in a call to gc()? I haven't experimented with a wide sample of
R code, but I don't usually encounter gc() as a major entry in my
Rprof() outputs.

-- 
Best regards,
Ivan



More information about the R-help mailing list