Skip to content

GH-140638: Add a GC "duration" stat#141720

Merged
brandtbucher merged 5 commits into
python:mainfrom
brandtbucher:gc-duration
Nov 19, 2025
Merged

GH-140638: Add a GC "duration" stat#141720
brandtbucher merged 5 commits into
python:mainfrom
brandtbucher:gc-duration

Conversation

@brandtbucher

@brandtbucher brandtbucher commented Nov 18, 2025

Copy link
Copy Markdown
Member

This adds a useful "duration" stat to gc.get_stats and gc.callbacks. It also fixes an issue where the existing timer could be used uninitialized if the GC's debug flags are set during a collection.


📚 Documentation preview 📚: https://cpython-previews--141720.org.readthedocs.build/

@brandtbucher brandtbucher self-assigned this Nov 18, 2025
@brandtbucher brandtbucher added type-feature A feature request or enhancement interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Nov 18, 2025
Comment thread Doc/library/gc.rst
* ``uncollectable`` is the total number of objects which were found
to be uncollectable (and were therefore moved to the :data:`garbage`
list) inside this generation.
list) inside this generation;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
list) inside this generation;
list) inside this generation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I just did this for consistency with the above points, haha.

Comment thread Python/gc_free_threading.c Outdated
@@ -1928,7 +1928,8 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
info = Py_BuildValue("{sisnsn}",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need to change this line to

Suggested change
info = Py_BuildValue("{sisnsn}",
info = Py_BuildValue("{sisnsnsd}",

no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice catch, thanks. Annoying that it just ignores trailing args like that.

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM I left some comments

@IsmaNegey

This comment was marked as spam.

@brandtbucher brandtbucher merged commit 598d4c6 into python:main Nov 19, 2025
46 checks passed
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
ashm-dev pushed a commit to ashm-dev/cpython that referenced this pull request Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants