Repository navigation
gh-159137: Skip redundant GC resurrection analysis - #159138
Merged
pablogsal merged 1 commit intoOct 10, 2026
Merged
Conversation
pablogsal
force-pushed
the
investigate/gc-pass-fusion-20261010
branch
from
October 10, 2026 19:00
239991d to
86ae540
Compare
nascheme
reviewed
Oct 10, 2026
nascheme
approved these changes
Oct 10, 2026
nascheme
left a comment
Member
There was a problem hiding this comment.
LGTM! I think we should apply the same kind of optimization to the free-threaded GC. I can do that, unless you want to.
maurycy
reviewed
Oct 10, 2026
pablogsal
force-pushed
the
investigate/gc-pass-fusion-20261010
branch
2 times, most recently
from
October 10, 2026 21:54
d46924d to
93b25be
Compare
sergey-miryanov
approved these changes
Oct 10, 2026
sergey-miryanov
left a comment
Contributor
There was a problem hiding this comment.
One small nit, otherwise looks good to me!
pablogsal
force-pushed
the
investigate/gc-pass-fusion-20261010
branch
from
October 10, 2026 22:13
93b25be to
8a5bd9a
Compare
pablogsal
enabled auto-merge (squash)
October 10, 2026 22:18
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.
An easy win! :) The GC currently does a second reachability check because callbacks can make objects reachable again. If no weakref callback, finalizer that could run Python code, or debug writer ran, we can reuse the first result and skip that check. The finalization scan still runs. Finished generators, coroutines, and async generators use this path because their finalizers are no-ops. Free-threaded builds also skip the extra stop-the-world pause. The measurements below use a GIL-enabled build and predate the optimization for finished generators.
Microbenchmarks
Here each case uses 100,000 objects or allocation iterations. Values are median CPU milliseconds from six processes per case, with seven samples after two warmups. Explicit collections exclude graph construction.
__del__Macrobenchmarks
A bunch of real programs tht hevily use GC. Sphinx 8.2.3 builds all CPython HTML documentation with one worker and fresh caches: 559 source files, 599 HTML files. Mypy 2.4.0 checks its own
mypyandmypycpackages: 346 files, without incremental caches or workers. A separate mypy run uses--no-fast-exit, then explicitly collects its analysis graph.Values are medians from 10 runs per executable, in baseline/candidate/candidate/baseline order. Application CPU time includes imports and command execution. GC durations come from native
gc.get_stats()counters. Cleanup collections are separate from application time.--no-fast-exit--no-fast-exit, separate cleanupRelated to #159137.