Analyzes the profile to detect excessive garbage collection, which is a universal indicator of memory allocation issues in R code.
Value
A data frame with columns:
severity: "high" (>25%), "medium" (>15%), or "low" (>threshold%)pct: Percentage of total time spent in GCtime_ms: Time spent in garbage collectionissue: Short description of the problemcause: What typically causes this issueactions: Comma-separated list of things to look for
Returns an empty data frame (0 rows) if GC is below the threshold.
Details
GC pressure above 10% typically indicates the code is allocating and discarding memory faster than necessary. Common causes include:
Growing vectors with
c(x, new)instead of pre-allocationBuilding data frames row-by-row with
rbind()Creating unnecessary copies of large objects
String concatenation in loops
Examples
p <- pv_example("gc")
pv_gc_pressure(p)
#> severity pct time_ms issue cause
#> 1 high 40 40 High GC overhead (40.0%) Excessive memory allocation
#> actions
#> 1 growing vectors, repeated data frame ops, unnecessary copies
# More sensitive detection
pv_gc_pressure(p, threshold = 5)
#> severity pct time_ms issue cause
#> 1 high 40 40 High GC overhead (40.0%) Excessive memory allocation
#> actions
#> 1 growing vectors, repeated data frame ops, unnecessary copies
# No GC pressure in default example
p2 <- pv_example()
pv_gc_pressure(p2)
#> [1] severity pct time_ms issue cause actions
#> <0 rows> (or 0-length row.names)
