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-139951: Fix major GC performance regression by markshannon · Pull Request #140262 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented Oct 17, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

This PR:

  • Counts number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead
  • Does not track most untrackable tuples during creation. This prevents large numbers of small tuples causing excessive GCs.

For the example in the original report this makes performance on main a bit better than 3.13.

Benchmarking results show this is about neutral on performance otherwise.

  • Issue: Potentially serious regression in garbage collector performance in Python 3.14 #139951

Sorry, something went wrong.

Uh oh!

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

All reactions
@markshannon
Fix major GC performance regression
2e8d020
* Count number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead
* Do not track most untrackable tuples during creation. This prevents large numbers of small tuples causing execessive GCs.
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 17, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Oct 17, 2025
Potentially serious regression in garbage collector performance in Python 3.14 #139951
Closed
@markshannon markshannon added needs backport to 3.14 bugs and security fixes and removed awaiting core review labels Oct 17, 2025
@markshannon
Add news
6c78c01
eendebakpt
eendebakpt reviewed Oct 17, 2025
View reviewed changes
Comment thread Objects/tupleobject.c Resolved

Uh oh!

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

sergey-miryanov
sergey-miryanov reviewed Oct 18, 2025
View reviewed changes
Comment thread Python/gc.c Resolved

Uh oh!

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

sergey-miryanov
sergey-miryanov reviewed Oct 18, 2025
View reviewed changes
Comment thread Include/internal/pycore_gc.h Resolved

Uh oh!

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

sergey-miryanov
sergey-miryanov reviewed Oct 18, 2025
View reviewed changes
Comment thread Python/gc.c Resolved

Uh oh!

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

efimov-mikhail
efimov-mikhail reviewed Oct 18, 2025
View reviewed changes
Comment thread Include/internal/pycore_gc.h Resolved

Uh oh!

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

sergey-miryanov
sergey-miryanov reviewed Oct 18, 2025
View reviewed changes
Comment thread Python/gc.c Resolved

Uh oh!

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

@sergey-miryanov

sergey-miryanov commented Oct 18, 2025

Copy link
Copy Markdown
Contributor

I'm not sure I get what android (x86_64) fails.
I can propose two solutions:

  1. Change default value for work_to_do from -5000 to 0
  2. Or remove newly added condition
if (gcstate->work_to_do < 0) {
    return;
}
All reactions

Sorry, something went wrong.

Uh oh!

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

@efimov-mikhail efimov-mikhail mentioned this pull request Oct 18, 2025
gh-139951: Test on GC collection disabled if threshold is zero #140304
Merged
@mhsmith

mhsmith commented Oct 19, 2025

Copy link
Copy Markdown
Member

I'm not at all familiar with the garbage collector, but one of the ways that Android differs from the other platforms is that it runs all the test suite serially in a single process.

sergey-miryanov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

markshannon added 3 commits October 20, 2025 12:19
@markshannon
Address review comments
c5836be
@markshannon
Up limit to 100000
bde53f4
@markshannon
Remove erroneous comment
1c2030a
@markshannon
markshannon requested a review from sergey-miryanov October 21, 2025 10:29
sergey-miryanov
sergey-miryanov reviewed Oct 21, 2025
View reviewed changes
Comment thread Python/gc.c Resolved

Uh oh!

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

sergey-miryanov
sergey-miryanov approved these changes Oct 21, 2025
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.

Code looks good to me, thanks!

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 21, 2025
@sergey-miryanov

sergey-miryanov commented Oct 21, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Should we redo the benchmarks to see how the final version impacts performance? Maybe we can run it on https://github.com/faster-cpython/benchmarking-public (but I don't know how).

All reactions

Sorry, something went wrong.

Uh oh!

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

efimov-mikhail
efimov-mikhail approved these changes Oct 21, 2025
View reviewed changes
Comment thread Include/internal/pycore_gc.h Resolved

Uh oh!

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

Comment thread Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-18-03-12.gh-issue-139951.IdwM2O.rst Resolved

Uh oh!

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

Comment thread Objects/tupleobject.c Resolved

Uh oh!

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

@markshannon
Address review comments
698e5f5
@markshannon
markshannon merged commit 0c01090 into python:main Oct 21, 2025
4 checks passed

Uh oh!

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

@miss-islington-app

miss-islington-app Bot commented Oct 21, 2025

Copy link
Copy Markdown

Thanks @markshannon for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting core review label Oct 21, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 21, 2025
@markshannon @miss-islington
pythonGH-139951: Fix major GC performance regression (pythonGH-140262)
f778f01
* Count number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead

* Do not track most untrackable tuples during creation. This prevents large numbers of small tuples causing execessive GCs.
(cherry picked from commit 0c01090)

Co-authored-by: Mark Shannon <[email protected]>
@bedevere-app

bedevere-app Bot commented Oct 21, 2025

Copy link
Copy Markdown

GH-140423 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 21, 2025
@ashm-dev ashm-dev mentioned this pull request Oct 21, 2025
Segfault in gc_free_threading.c after PR #140262 with ASAN build and free-threading tests #140431
Closed
@eendebakpt eendebakpt mentioned this pull request Oct 21, 2025
GH-140052: Add PyTuple_MakeSingle and PyTuple_MakePair #140132
Closed
@efimov-mikhail efimov-mikhail mentioned this pull request Oct 22, 2025
gh-1339951: Count only GC tracked objects in young, not all allocated #140215
Closed
markshannon added a commit that referenced this pull request Oct 23, 2025
@markshannon
[3.14] GH-139951: Fix major GC performance regression. Backport of GH…
d1a434f
…-140262 (GH-140447)

* Count number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead
* Do not track most untrackable tuples during creation. This prevents large numbers of small tuples causing execessive GCs.
This was referenced Oct 25, 2025
gh-139951: Tests on tuple tracking #140575
Merged
pickletools optimize performance degraded with factor 3-4 in python 3.14 #140175
Closed
nascheme added a commit to nascheme/cpython that referenced this pull request Nov 27, 2025
@nascheme
Revert GC changes to "work_to_do" logic.
fef3eed
This reverts parts of the pythonGH-140262 change.  The changes that affect the
tuple untracking are left unchanged.  Revert the changes to the
calculation of the increment size, based on the "work_to_do" variable.
This causes cyclic garbage to be collected more quickly.  Revert also
the change to test_gc.py, which was done because the expected GC
collection was taking longer to happen.

With the tuple untrack change, the performance regression as reported by
bug pythonGH-139951 is still resolved (work_to_do changes are not required).
This was referenced Nov 27, 2025
GH-142002: Revert GC changes to "work_to_do" logic. #142001
Closed
Incremental GC does not collect garbage as soon as expected #142002
Open
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@markshannon @StanFromIreland
pythonGH-139951: Fix major GC performance regression (pythonGH-140262)
99c908c
* Count number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead

* Do not track most untrackable tuples during creation. This prevents large numbers of small tuples causing execessive GCs.
@MaxiBoether MaxiBoether mentioned this pull request Dec 10, 2025
[3.14t] Free-threaded GC performance regression on tuples #142531
Closed
@nascheme nascheme mentioned this pull request Dec 18, 2025
Observed memory leak in ssl library: Python 3.14 GC issue #142516
Closed
sergey-miryanov pushed a commit to sergey-miryanov/cpython that referenced this pull request Jan 24, 2026
@nascheme @sergey-miryanov
Revert GC changes to "work_to_do" logic.
a9a2252
This reverts parts of the pythonGH-140262 change.  The changes that affect the
tuple untracking are left unchanged.  Revert the changes to the
calculation of the increment size, based on the "work_to_do" variable.
This causes cyclic garbage to be collected more quickly.  Revert also
the change to test_gc.py, which was done because the expected GC
collection was taking longer to happen.

With the tuple untrack change, the performance regression as reported by
bug pythonGH-139951 is still resolved (work_to_do changes are not required).
sergey-miryanov pushed a commit to sergey-miryanov/cpython that referenced this pull request Jan 25, 2026
@nascheme @sergey-miryanov
Revert GC changes to "work_to_do" logic.
efd2a4c
This reverts parts of the pythonGH-140262 change.  The changes that affect the
tuple untracking are left unchanged.  Revert the changes to the
calculation of the increment size, based on the "work_to_do" variable.
This causes cyclic garbage to be collected more quickly.  Revert also
the change to test_gc.py, which was done because the expected GC
collection was taking longer to happen.

With the tuple untrack change, the performance regression as reported by
bug pythonGH-139951 is still resolved (work_to_do changes are not required).
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
@eendebakpt eendebakpt eendebakpt left review comments
@efimov-mikhail efimov-mikhail efimov-mikhail approved these changes

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.

5 participants

@markshannon @sergey-miryanov @mhsmith @eendebakpt @efimov-mikhail
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.