mirror of
https://github.com/python/cpython.git
synced 2026-02-22 07:00:51 +00:00
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>
This commit is contained in:
parent
638d22c6e7
commit
d891b2bbd1
12 changed files with 254 additions and 106 deletions
|
|
@ -2392,10 +2392,9 @@ dummy_func(
|
|||
}
|
||||
else {
|
||||
/* Classic, pushes one value. */
|
||||
PyObject *attr_o = PyObject_GetAttr(PyStackRef_AsPyObjectBorrow(owner), name);
|
||||
attr = _PyObject_GetAttrStackRef(PyStackRef_AsPyObjectBorrow(owner), name);
|
||||
PyStackRef_CLOSE(owner);
|
||||
ERROR_IF(attr_o == NULL);
|
||||
attr = PyStackRef_FromPyObjectSteal(attr_o);
|
||||
ERROR_IF(PyStackRef_IsNull(attr));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue