]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-154401: Skip fetching the thread state for non-GC types in `_Py_Dealloc` (GH-154430)
authorJohn <me@joh.ng>
Wed, 22 Jul 2026 22:43:18 +0000 (23:43 +0100)
committerGitHub <noreply@github.com>
Wed, 22 Jul 2026 22:43:18 +0000 (18:43 -0400)
commit6fb51f23f7973560c009552c61e86955584a2fb2
tree1c42a65d3c39c0da5de6287c60bd3726d9068f03
parenta2a846678e54b1b5defdccd451c573679094ff02
gh-154401: Skip fetching the thread state for non-GC types in `_Py_Dealloc` (GH-154430)

_Py_Dealloc() fetched the current thread state and computed the C
recursion margin on every deallocation, but both are only used by the
trashcan mechanism, which applies only to GC-tracked types. Gate them
behind the Py_TPFLAGS_HAVE_GC check so the common non-GC case (int,
float, str and similar atomic types) skips them.

On platforms where _PyThreadState_GET() reads a _Thread_local via a
function call (e.g. macOS TLV), this removes a call from every non-GC
deallocation.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Misc/NEWS.d/next/Core_and_Builtins/2026-07-22-14-30-00.gh-issue-154429.Qk9mZ2.rst [new file with mode: 0644]
Objects/object.c