You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use pystats for free threading performance statistics #131253
It'd be helpful to have a counter for lock contention (the number of times a thread blocks on a lock acquisition), especially in the free threading builds. We already have infrastructure to record Python statistics in pystats.h. It'd be great to extend this.
I think there are a few steps needed to support this:
pystats should be thread-safe in the free threading build and not inhibit multithreaded scaling. In practice, I think this means that stats should be recorded per-thread and aggregated when a thread exits (and possibly aggregated more often as well).
Some stats are cheap to collect and widely useful, including the above mentioned lock contention and some GC stats. We should consider recording some stats even when Python isn't built with --enable-pystats so that they are available in release builds, while being careful not to regress performance.
Consider providing a Python API for retrieving stats in addition to the existing behavior of dumping stat counters to a file. We don't have to pursue this immediately, but I think it'd be useful in the same ways that gc.get_stats() is useful.
Free threading stats:
Lock contention counter (number of times a thread blocks on a lock acquisition)
Stop the world counter (and possibly total duration)
The FT build currently doesn't support ring-buffer statistics like the GIL build does (it sets all ring-buffer sizes to 1). If we want to support this, I will open a PR. Does this make sense?
Activity
pythongh-131253: free-threaded build support for pystats
Merge 'origin/main' into pythongh-131253-pystats-ft
Merge 'origin/main' into pythongh-131253-pystats-ft
Merge 'origin/main' into pythongh-131253-pystats-ft
Merge 'origin/main' into pythongh-131253-pystats-ft
gh-131253: free-threaded build support for pystats (gh-137189)
pythongh-131253: free-threaded build support for pystats (pythongh-13…
kumaraditya303 commentedon Jul 23, 2026
I think this is complete now.
sergey-miryanov commentedon Jul 28, 2026
The FT build currently doesn't support ring-buffer statistics like the GIL build does (it sets all ring-buffer sizes to 1). If we want to support this, I will open a PR. Does this make sense?