]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-139103: Improve namedtuple scaling in free-threaded build (gh-144332)
authorSam Gross <colesbury@gmail.com>
Fri, 6 Feb 2026 14:43:05 +0000 (09:43 -0500)
committerGitHub <noreply@github.com>
Fri, 6 Feb 2026 14:43:05 +0000 (09:43 -0500)
commitd891b2bbd16c25995df853121d2f134d3e357cd1
treeb722044ddd93cb2a82eda0d4a241211428879c0f
parent638d22c6e7b129fcec7fa471abd8ffca62e54cd6
gh-139103: Improve namedtuple scaling in free-threaded build (gh-144332)

Add `_Py_type_getattro_stackref`, a variant of type attribute lookup
that returns `_PyStackRef` instead of `PyObject*`. This allows returning
deferred references in the free-threaded build, reducing reference count
contention when accessing type attributes.

This significantly improves scaling of namedtuple instantiation across
multiple threads.

* Add blurb

* Rename PyObject_GetAttrStackRef to _PyObject_GetAttrStackRef

* Apply suggestion from @vstinner

Co-authored-by: Victor Stinner <vstinner@python.org>
* Apply suggestion from @vstinner

Co-authored-by: Victor Stinner <vstinner@python.org>
* format

* Update Include/internal/pycore_function.h

Co-authored-by: Victor Stinner <vstinner@python.org>
---------

Co-authored-by: Victor Stinner <vstinner@python.org>
12 files changed:
Include/internal/pycore_function.h
Include/internal/pycore_object.h
Include/internal/pycore_typeobject.h
Misc/NEWS.d/next/Core_and_Builtins/2026-01-29-16-57-11.gh-issue-139103.icXIEQ.rst [new file with mode: 0644]
Modules/_testinternalcapi/test_cases.c.h
Objects/funcobject.c
Objects/object.c
Objects/typeobject.c
Python/bytecodes.c
Python/executor_cases.c.h
Python/generated_cases.c.h
Tools/ftscalingbench/ftscalingbench.py