Visitar URL original
Promote retained GC objects and batch generation updates by 1ndahous3 · Pull Request #8930 · RustPython/RustPython · GitHub
Skip to content

Promote retained GC objects and batch generation updates - #8930

Merged
youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:gc_survivor_promotion
Oct 1, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:gc_survivor_promotion

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Promote young survivors of a full collection to generation 2, so the next young collection does not revisit them.
  • Promote resurrected objects and garbage retained by DEBUG_SAVEALL to the next generation, capped at generation 2.
  • Batch generation-list locking and atomic counter updates, releasing the locks between bounded batches.

Follow-up to #8902.

Performance

Windows 11 x64

Release build; median collection time, excluding heap construction.

Collection Before After Speedup
Young generation, 2,000 live lists 0.156 ms 0.131 ms 1.19×
Young generation, 20,000 live lists 1.762 ms 1.191 ms 1.48×
Young generation with 2,000 new lists after a full collection of 20,000 retained lists 1.520 ms 0.144 ms 10.58×

AI assistance

Written with Codex (GPT-6), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • Objects that survive garbage collection are now assigned to the appropriate generation, including after a full collection.
    • Resurrected objects and objects retained for debugging are promoted consistently, helping ensure they remain managed correctly in later collections.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: RustPython/RustPython/.coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: dde749ad-14a1-45e6-b05c-6de633fc668c

📥 Commits

Reviewing files that changed from the base of the PR and between cb0f3b0 and ca8e09f.

📒 Files selected for processing (2)
  • crates/vm/src/gc_state.rs
  • extra_tests/snippets/stdlib_gc.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Garbage collection now promotes surviving objects to generation 2 during full collections. Resurrected and SAVEALL-retained objects are also promoted. Rust and Python tests cover generation placement and tracking consistency.

Changes

Garbage collector survivor promotion

Layer / File(s) Summary
Promotion targets and list updates
crates/vm/src/gc_state.rs
promote_survivors targets min(from_gen + 1, 2), processes survivors in batches, and updates counts for objects actually moved. A Rust test covers mixed generations, frozen and untracked objects, and list/count consistency.
Retained-object promotion
crates/vm/src/gc_state.rs, extra_tests/snippets/stdlib_gc.py
Resurrected and SAVEALL-retained objects are promoted before retention. Python tests check generation placement for survivors and retained cycles after collections.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: youknowone

Merge Risk: ⚪ Minimal · up to ca8e0

This change promotes GC survivors to generation 2 and batches list updates, which should reduce young-collection cost. No concrete merge-blocking issue was identified, and tests cover generation placement and list consistency.

Security Architecture Review

Security architecture risk: 🔵 Low · up to ca8e0

The changes preserve ownership filtering and object-tracking checks. No introduced security vulnerability was identified, but shared object-lifetime transitions and concurrent execution have only source-level validation in this review.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The security-relevant failure domain is in-process object lifetime and shared generation-list integrity, potentially affecting interpreters sharing the process. The inspected changes do not expand filesystem, network, credential, or service authority.

Security Findings and Attack Paths

  • inferred — User-created cycles, finalizers, and SAVEALL settings reach the changed promotion paths through existing collection behavior. The inspected transitions do not establish a new cross-owner exposure or object-lifetime attack path: ownership is preserved, references remain strong, and membership is rechecked under locks.

Trust Boundaries and Controls

  • observed — Existing controls remain in place: collection is serialized with a collecting lock, generation selection is capped at 2, candidate selection filters ownership, and promotion holds both list locks while checking tracked status and moving each node. The new Heap and Drop code is confined to a regression test, not a production entrypoint.

Resilience and Maintainability Implications

  • inferred — Repetition and stale snapshots are contained by tracked-state and generation rechecks; concurrent untracking retries if promotion changed the generation. Each successful move completes under both locks without invoking user callbacks. These mechanisms support lifetime and list-integrity guarantees, although arbitrary scheduling and interruption were not validated at runtime.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise, specific, and accurately summarizes the two main changes: promoting retained GC objects and batching generation updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone merged commit 112b7ef into RustPython:main Oct 1, 2026
30 checks passed
@1ndahous3
1ndahous3 deleted the gc_survivor_promotion branch October 8, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants