Repository navigation
gh-159137: gc: Count GC survivors in untrack_tuples() instead of walking the young generation again - #159149
Closed
maurycy wants to merge 2 commits into
Closed
gh-159137: gc: Count GC survivors in untrack_tuples() instead of walking the young generation again#159149maurycy wants to merge 2 commits into
gc: Count GC survivors in untrack_tuples() instead of walking the young generation again#159149maurycy wants to merge 2 commits into
Conversation
maurycy
marked this pull request as ready for review
October 10, 2026 21:22
Contributor
Author
Member
|
This is subset of another PR I m finishing now :) |
Member
|
See #159154 |
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.
Inspired by #159137.
After
deduce_unreachable(),gc_collect_main()walks the surviving young generation twice.untrack_tuples()visits every object:cpython/Python/gc.c
Lines 664 to 676 in 9028df3
and then
gc_list_size(young)walks the same list again only to updatelong_lived_pendingorlong_lived_total:cpython/Python/gc.c
Lines 1517 to 1535 in 9028df3
So the idea is to
untrack_tuples()to return the number of objects that stay tracked, and use it instead ofgc_list_size(young).Microbenchmark
Full collections on a heap that stays alive for the whole run. macOS 27 (M4 Air), release build w/o PGO. Median of 6 processes per binary, interleaved A/B/B/A:
main(9028df3)9028df3+ patchUnfortunately, I don't have access to Linux baremetal at the moment.
Macrobenchmark
Sphinx 8.2.3 building the CPython HTML docs with one worker and fresh doctrees (
sphinx-build -b html -j 1 -E), same machine and builds, 6 runs per binary interleaved A/B/B/A. GC time is the sum ofdurationfromgc.get_stats()main(9028df3)9028df3+ patchMicrobenchmark