SIGN IN SIGN UP
python / cpython UNCLAIMED

The Python programming language

0 0 0 Python

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 <[email protected]>

* Apply suggestion from @vstinner

Co-authored-by: Victor Stinner <[email protected]>

* format

* Update Include/internal/pycore_function.h

Co-authored-by: Victor Stinner <[email protected]>

---------

Co-authored-by: Victor Stinner <[email protected]>
S
Sam Gross committed
d891b2bbd16c25995df853121d2f134d3e357cd1
Parent: 638d22c
Committed by GitHub <[email protected]> on 2/6/2026, 2:43:05 PM