gc: Stop objects awaiting finalization from triggering full collections #64029
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 493 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.371
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #64029"
general
weight: 0.35
topolarity
When the GC finds dead objects with pending finalizers, it marks them through the
to_finalizelist so that their finalizers can run. They are garbage once those finalizers have run. That marking was counted inscanned_bytes, and therefore inpromoted_bytes. As a result, code that creates many short-lived objects with finalizers (BigInt/BigFloatarithmetic is the common case) kept tripping the "large promotion rate" heuristic (promoted_bytes / heap_size > 0.15). It ended up doing a full collection about every other GC, each of which re-marks all long-lived data.This PR does two things:
1. Bytes marked through
to_finalizeare no longer counted as promoted.2. Pages that held such cells are flagged (
has_finalized) so the next quick sweep visits them.The second part is needed because those full collections were also doing real work. After the sweep, a cell that was marked only to run its finalizer is promoted like any other marked cell, and the page's
has_youngis cleared. On a page holding nothing else, that's harmless: at the next collection nothing on the page is marked, so the whole page is freed. On a page that also holds a live old object, though, quick sweeps skip the page, and the finalized cells were only reclaimed by full collections. With the flag, the next quick sweep frees them.Reproducer: full collections
Before:
After:
These numbers were measured on top of https://github.com/JuliaLang/julia/pull/64027 (the
BigIntheap-size accounting fix), so that only this change differs.The effect is not specific to
BigInt. A plainmutable structwith a finalizer, churned the same way, does one promotion-triggered full collection per round on master and none with this change. How much time is saved depends on the size of the long-lived heap, since each avoided full collection would have re-marked all of it.Reproducer: finalized objects sharing pages with live objects
This checks that removing those full collections doesn't leave memory behind. One in 1024 finalizable objects is kept alive for a while, so live and finalized objects share pages:
About 1 MB is actually live. Memory held after a young GC in rounds 4–12:
The roughly 153 MB in both builds is the last round's objects, whose finalizers ran after that collection; the next collection frees them.
🤖 Generated with Claude Code