[R] summaryRprof: Unexpected unit for memory profiling

Sauer, Lukas Daniel @@uer @end|ng |rom |mb|@un|-he|de|berg@de
Mon Jul 1 15:33:43 CEST 2024


Hello,

I am profiling memory usage using utils::Rprof() and subsequently summarizing the profile using utils::summaryRprof(). According to the documentation ?summaryRprof, the option `memory = "both"` reports "memory consumption in Mb in addition to the timings", i.e. the unit is megabytes. However, looking at the source code (https://github.com/wch/r-source/blob/18652de8890d89563b923ff58b45ccb04d9955fe/src/library/utils/R/summRprof.R#L170) suggests that memory is reported in mebibytes (division by 1048576 and not by 100000). This is in line with the following minimal example:

use_mb <- function(){a <- runif(1000000)}
use_mib <- function(){b <- runif(1024^2)}
Rprof("Rprof.out", memory.profiling=TRUE)
use_mb()
use_mib()
Rprof(NULL)
summaryRprof("Rprof.out", memory="both")

Do not source this code, but execute it line by line. This example returns the output:

$by.self
        self.time self.pct total.time total.pct mem.total
"runif"      0.04      100       0.04       100      15.6

$by.total
          total.time total.pct mem.total self.time self.pct
"runif"         0.04       100      15.6      0.04      100
"use_mb"        0.02        50       7.6      0.00        0
"use_mib"       0.02        50       8.0      0.00        0

$sample.interval
[1] 0.02

$sampling.time
[1] 0.04

The example was run under:

R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

If the unit were megabytes, I would expect mem.total to be 16.4, 8.0, and 8.4 -- but rather it is 15.6, 7.6, and 8.0. Do you agree that this behavior is unexpected or did I overlook something? If yes, I will file a bug report and suggest that the documentation is changed to "memory consumption in MiB in addition to the timings".

Best regards,

Lukas D Sauer
Biometrician
Institute of Medical Biometry

Heidelberg University Hospital | Im Neuenheimer Feld 130.3 | D-69120 Heidelberg
Tel. +49 6221 56-35036 | Fax. +49 6221 56-4195 | E-Mail: sauer using imbi.uni-heidelberg.de
biometrie.uni-heidelberg.de | twitter.com/imbi_heidelberg



More information about the R-help mailing list