Repository navigation
gh-159437: Combine GC reference passes - #159599
Draft
mfalco-oai wants to merge 4 commits into
Draft
mfalco-oai wants to merge 4 commits into
mfalco-oai wants to merge 4 commits into
Conversation
Count the stable unreachable set while preparing callbacks and retain a conservative cleanup flag. Reuse the count only when late weakref clearing has no work, and force fresh cleanup and counting after resurrection analysis. Add a regression for a callback-free weakref observed when clearing a young cycle releases an older finalizer.
pablogsal
reviewed
Oct 17, 2026
| /* Monotonic guard for tracked objects that may outlive their interpreter. | ||
| * Kept outside _PyRuntime so reinitialization cannot clear it. | ||
| */ | ||
| static int may_have_foreign_gc_objects; |
Member
There was a problem hiding this comment.
This condition is only used by GC. A simular guard I used in an earlier PR lived in gc.c and was updated from _PyGC_InitState, which avoided another accessor and declaration.
Is there a lifecycle case that needs this set before GC state initialization? Otherwise we could keep it local to GC, while still remembering previous interpreters after teardown and runtime restart.
| 'bar()\n') | ||
| # Full GIL collections may skip update_refs(). Stop at a visible phase | ||
| # after the collector marks collection active. | ||
| if support.Py_GIL_DISABLED: |
Member
There was a problem hiding this comment.
Why not use gc_collect_main regardless of the GIL? The collectors have it and the GDB helper already recognizes it. There's an example in an earlier PR, where I made the same breakpoint change. That would remove this branch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With this optimization the GIL collector initializes temporary reference counts while subtracting references within the collection. Initializing each count on first encounter combines two walks over the objects into one.
The combined pass is limited to the initial reachability analysis of full collections. It requires an empty permanent generation and is disabled after any subinterpreter reservation or runtime reinitialization. These restrictions ensure every tracked mortal referent is part of the collection. Young collections and resurrection checks keep the existing passes.