use stackrefs in _PyObject_GetMethod and calling APIs
#134043
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
performance
Performance or resource usage
topic-free-threading
type-feature
A feature request or enhancement


Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Currently the calling APIs such as
PyObject_VectorcallMethoduse_PyObject_GetMethodto avoid creating a bound method object, however_PyObject_GetMethodincrefs and decrefs the object even when the underlying object supports deferred reference counting. This leads to reference counting contention on the object and it doesn't scale well in free threading. This API is heavily used by modules such as asyncio so it is important that_PyObject_GetMethodshould scale well with threads.cpython/Objects/call.c
Lines 829 to 859 in 54a6875
Proposal:
To take advantage of deferred reference counting, we should add stack ref variant of
_PyObject_GetMethodand use it in all calling APIs to avoid reference counting contention on the function object.Implementation:
_PyObject_GetMethodStackRefwill use_PyType_LookupStackRefAndVersionwhen looking up method from type cache._PyObject_TryGetInstanceAttributeStackRefwill be added to to be used with_PyObject_GetMethodStackRef._Py_dict_lookup_threadsafe_stackref.cpython/Objects/object.c
Lines 1632 to 1640 in 54a6875
Linked PRs
_PyObject_GetMethodStackRef#134044The text was updated successfully, but these errors were encountered: