GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-159137: Skip redundant GC resurrection analysis by pablogsal · Pull Request #159138 · python/cpython

Conversation

@pablogsal

@pablogsal pablogsal commented Oct 10, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

Workload Before After Less CPU time
Retained lists 1.552 ms 1.565 ms -0.79%
Retained nested tuples 2.548 ms 2.571 ms -0.94%
Unreachable list cycles 4.276 ms 3.867 ms 9.55%
Unreachable dictionary cycles 5.498 ms 3.565 ms 35.16%
Unreachable instance cycles 5.984 ms 5.271 ms 11.92%
Instance cycles with a no-op __del__ 11.785 ms 10.744 ms 8.84%
Cyclic list allocation with automatic GC 9.533 ms 8.456 ms 11.29%
Acyclic dictionary/list allocation with automatic GC 10.603 ms 8.706 ms 17.90%

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 mypy and mypyc packages: 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.

Workload Before (mean CPU time) After (mean CPU time)
Sphinx 78.275 s 70.560 s
Sphinx, separate cleanup 0.687 s 0.656 s
Mypy 26.059 s 26.072 s
Mypy with --no-fast-exit 27.043 s 26.354 s
Mypy with --no-fast-exit, separate cleanup 1.397 s 1.247 s

Related to #159137.

  • Issue: Speed up garbage collector #159137

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

maurycy reacted with heart emoji sergey-miryanov reacted with rocket emoji
All reactions
  • ❤️ 1 reaction
  • 🚀 1 reaction
@pablogsal
pablogsal requested review from nascheme and sergey-miryanov October 10, 2026 18:51
@bedevere-app bedevere-app Bot mentioned this pull request Oct 10, 2026
Speed up garbage collector #159137
Open
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 10, 2026
@pablogsal
pablogsal force-pushed the investigate/gc-pass-fusion-20261010 branch from 239991d to 86ae540 Compare October 10, 2026 19:00
nascheme
nascheme reviewed Oct 10, 2026
View reviewed changes
Comment thread Python/gc.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

nascheme
nascheme approved these changes Oct 10, 2026
View reviewed changes

@nascheme nascheme left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I think we should apply the same kind of optimization to the free-threaded GC. I can do that, unless you want to.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Oct 10, 2026
maurycy
maurycy reviewed Oct 10, 2026
View reviewed changes
Comment thread Python/gc.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal force-pushed the investigate/gc-pass-fusion-20261010 branch 2 times, most recently from d46924d to 93b25be Compare October 10, 2026 21:54
@pablogsal
pablogsal requested a review from markshannon as a code owner October 10, 2026 21:54
sergey-miryanov
sergey-miryanov approved these changes Oct 10, 2026
View reviewed changes

@sergey-miryanov sergey-miryanov left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small nit, otherwise looks good to me!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/gc.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pythongh-159137: Skip redundant GC resurrection analysis
8a5bd9a
@pablogsal
pablogsal force-pushed the investigate/gc-pass-fusion-20261010 branch from 93b25be to 8a5bd9a Compare October 10, 2026 22:13
@pablogsal
pablogsal enabled auto-merge (squash) October 10, 2026 22:18
@pablogsal
pablogsal merged commit fbbf4f4 into python:main Oct 10, 2026
55 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal deleted the investigate/gc-pass-fusion-20261010 branch October 10, 2026 22:46
@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 10, 2026
orsenthil pushed a commit to orsenthil/cpython that referenced this pull request Oct 11, 2026
@pablogsal @orsenthil
pythongh-159137: Skip redundant GC resurrection analysis (python#159138)
79006ef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sergey-miryanov sergey-miryanov sergey-miryanov approved these changes
@nascheme nascheme nascheme approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
+1 more reviewer
@maurycy maurycy maurycy left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@pablogsal @maurycy @sergey-miryanov @nascheme
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.