gh-128807: Add marking phase for free-threaded cyclic GC#128808
Merged
Uh oh!
There was an error while loading. Please reload this page.
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.
This is conceptually similar to the phase that was added to the non-free-threaded GC. Start with a set of known root objects, like sysdict and mark all objects reachable from those (revealed by the tp_traverse method) as "alive". We know anything marked alive cannot be garbage and can be excluded from the regular cyclic GC process. For most programs, this saves a moderate amount of computation since the marking pass is relatively cheaper per object.
If
gc.freeze()is used, it's unlikely that this marking phase will be a win since it's expected that the majority of objects will be frozen. Disable the marking phase if freeze is used.See gh-126491 for the non-free-threaded version of this technique.
pyperformance results vs merge base. I suspect the slowdown on some benchmarks is not real. For example, regex_v8 should not be slower.
Here are the pyperformance results for a bare-metal AMD Ryzen machine. It does not show a slowdown on regex_v8, for example.
To better show the expected improvement, I ran a "sphinx build" benchmark, like in gh-124567. Results are: