Repository navigation
gh-159437: Remove extra resurrection bookkeeping walks - #159595
Draft
mfalco-oai wants to merge 6 commits into
Draft
mfalco-oai wants to merge 6 commits into
mfalco-oai wants to merge 6 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.
Count tp_del candidates during the existing reference traversals so zero can skip legacy classification. Reuse callback preparation to clear initial unreachable tags, while preserving normalized links before DEBUG_COLLECTABLE output can invoke Python. Cover debug visibility of weakrefs with callbacks and legacy classification during a generation 0 collection.
pablogsal
reviewed
Oct 17, 2026
| if (resurrection_checked) { | ||
| collectable = &final_unreachable; | ||
| // Python code may have changed the garbage set or created weakrefs. | ||
| // Refresh cleanup and counting, and normalize the recheck's tags. |
Member
There was a problem hiding this comment.
Small naming thing: needs_weakref_cleanup now also means the list links need their tags cleared, even when there are no weakrefs. The comment explains that, but the condition below still reads as though it only controls weakrefs. Maybe a name that covers this extra cleanup work?
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 removes two bookkeeping walks around a resurrection recheck.
update_refs()already replaces the temporary state, so the collecting bits do not need a separate clearing pass before the recheck.clear_weakrefs()clears the unreachable tags during its required walk over the remaining garbage, leaving the list normalized before deletion.