]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-146527: Heap-allocate gc_stats to avoid bloating PyInterpreterState (#148057)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Sat, 4 Apr 2026 17:42:30 +0000 (18:42 +0100)
committerGitHub <noreply@github.com>
Sat, 4 Apr 2026 17:42:30 +0000 (18:42 +0100)
commit21fb9dc71d2dd4ea9faf966385c102be20ce99e8
treeeaba742f5c33b69d3974eb39f7c7049266ae7fd8
parentb1d2d9829cfb33f0487ce00c19fa57ddefeb1b50
gh-146527: Heap-allocate gc_stats to avoid bloating PyInterpreterState (#148057)

The gc_stats struct contains ring buffers of gc_generation_stats
entries (11 young + 3×2 old on default builds). Embedding it inline
in _gc_runtime_state, which is itself inline in PyInterpreterState,
pushed fields like _gil.locked and threads.head to offsets beyond
what out-of-process profilers and debuggers can reasonably read in
a single buffer (e.g. offset 9384 for _gil.locked vs an 8 KiB read
buffer).

Heap-allocate generation_stats via PyMem_RawCalloc in _PyGC_Init and
free it in _PyGC_Fini. This shrinks PyInterpreterState by ~1.6 KiB
and keeps the GIL, thread-list, and other frequently-inspected fields
at stable, low offsets.
Include/internal/pycore_interp_structs.h
Modules/gcmodule.c
Python/gc.c
Python/gc_free_threading.c