← Back to Pull requests

gc: Fix GC heap size growing without bound with BigInt use #64027

Closed
unknown closed this pull request without merging on Oct 22, 2026 20:35 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 11:46 UTC
Author

The counted allocators add the usable size of the block (memory_block_usable_size) to heap_size on allocation, but GMP's free and realloc hooks (jl_gmp_counted_free_with_size,
jl_gmp_counted_realloc_with_old_size) subtracted the size GMP requested. Every BigInt allocation therefore left its allocator slack in heap_size and live_bytes forever: after 20M big(i) the GC accounted for 460 MB while 46 MB was resident. Once the phantom heap passes the heap-size hint, every collection becomes a full one, and with --hard-heap-limit the process eventually aborts.

Use the usable size of the block in the GMP hooks instead.

As an example:

# BigInt temporaries that die immediately; real live data stays tiny.
function f(n)
    s = 0
    for i in 1:n
        s += Int(big(i) % 7)
    end
    return s
end

f(10)
for k in 1:5
    a = Base.gc_num()
    f(4_000_000)
    b = Base.gc_num()
    GC.gc(true)
    println("round $k: gc_live_bytes = ", lpad(round(Int, Base.gc_live_bytes() / 2^20), 4), " MB, ",
            "GCs = ", lpad(b.pause - a.pause, 2), ", full GCs = ", lpad(b.full_sweep - a.full_sweep, 2))
end
println("Sys.maxrss() = ", Sys.maxrss() ÷ 2^20, " MB")

master:

round 1: gc_live_bytes =   97 MB, GCs = 23, full GCs = 11
round 2: gc_live_bytes =  191 MB, GCs = 45, full GCs = 11
round 3: gc_live_bytes =  286 MB, GCs = 42, full GCs = 38
round 4: gc_live_bytes =  378 MB, GCs = 30, full GCs = 30
round 5: gc_live_bytes =  474 MB, GCs = 23, full GCs = 23

PR:

round 1: gc_live_bytes =    9 MB, GCs = 25, full GCs = 12
round 2: gc_live_bytes =   19 MB, GCs = 24, full GCs = 12
round 3: gc_live_bytes =    7 MB, GCs = 24, full GCs = 12
round 4: gc_live_bytes =    4 MB, GCs = 23, full GCs = 12
round 5: gc_live_bytes =    4 MB, GCs = 23, full GCs = 12

Note that the actual memory usage is not a problem here, it is just the GC's own accounting, which drives its full-GC decisions and the hard limit. Also, the full GCs even in the PR state is another issue (dead BigInts waiting on finalizers are counted as promote).

Assisted-by: Claude Code (Claude Opus 5.5)

Diff: 264 lines (+198 / -66) across 3 files Reviewer: topolarity Review duration: 528m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 264 lines diff across 3 files
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.334
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #64027"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.3% (MEDIUM) · Higher = larger blast radius
39.3%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.5% · Safe to merge
15.5%