Я пытаюсь измерить пиковое использование памяти в некотором коде и пробовал несколько небольших примеров. summaryRprof
выдавал ошибки в некоторых других данных (не показаны), поэтому я начал возиться с внутренним анализатором profvis
. Я нахожу существенно разные значения для максимального использования памяти. Как это может быть, если они основаны на одних и тех же данных профилирования?
library(data.table)
library(profvis)
#avoid using a regular sequence for memory profiling because ALTREP will store it efficiently
x <- data.table(x1=sample(1:1e9,1e8,replace=TRUE),x2=sample(1:1e9,1e8,replace=TRUE))
gctorture(TRUE)
Rprof("prof1.out", memory.profiling=TRUE)
y1 <- rbind(x,x,x,x,x)
setkey(y1,x1) #sort to make sure copies of the columns in x are actually made
Rprof(NULL)
rm(y1)
Rprof("prof2.out", memory.profiling=TRUE)
y2 <- rbind(x,x,x,x,x,x,x,x,x,x)
setkey(y2,x1) #sort to make sure copies of the columns in x are actually made
Rprof(NULL)
rm(y2)
q3 <- data.table(a=1:5,k=1L)
q4 <- data.table(a=1:10,k=1L)
x[,k:=1L]
Rprof("prof3.out", memory.profiling=TRUE)
y3 <- q3[x,on=list(k),allow.cartesian=TRUE]
Rprof(NULL)
rm(y3)
Rprof("prof4.out", memory.profiling=TRUE)
y4 <- q4[x,on=list(k),allow.cartesian=TRUE]
Rprof(NULL)
rm(y4)
gctorture(FALSE)
z1 <- parse_rprof("prof1.out")
z2 <- parse_rprof("prof2.out")
z3 <- parse_rprof("prof3.out")
z4 <- parse_rprof("prof4.out")
Результаты:
> max(z1$prof$memalloc,na.rm=TRUE)
[1] 6494.122
> max(rowSums(summaryRprof("prof1.out", memory="tseries")[,1:3]))/(1e6)
[1] 2000
> max(z2$prof$memalloc,na.rm=TRUE)
[1] 12216.17
> max(rowSums(summaryRprof("prof2.out", memory="tseries")[,1:3]))/(1e6)
[1] 4000
>
>
>
> max(z3$prof$memalloc,na.rm=TRUE)
[1] 13742.09
> max(rowSums(summaryRprof("prof3.out", memory="tseries")[,1:3]))/(1e6)
[1] 2400
> max(z4$prof$memalloc,na.rm=TRUE)
[1] 13742.08
> max(rowSums(summaryRprof("prof4.out", memory="tseries")[,1:3]))/(1e6)
[1] 4400
SessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] profvis_0.3.6 data.table_1.12.2
loaded via a namespace (and not attached):
[1] htmlwidgets_1.5 compiler_3.6.1 magrittr_1.5 htmltools_0.3.6 tools_3.6.1
[6] yaml_2.2.0 Rcpp_1.0.1 stringi_1.4.3 stringr_1.4.0 digest_0.6.20