Skip to content

gh-145779: Improve classmethod/staticmethod scaling in free-threaded build#145826

Open
colesbury wants to merge 1 commit intopython:mainfrom
colesbury:gh-145779-classmethod-staticmethod-scaling
Open

gh-145779: Improve classmethod/staticmethod scaling in free-threaded build#145826
colesbury wants to merge 1 commit intopython:mainfrom
colesbury:gh-145779-classmethod-staticmethod-scaling

Conversation

@colesbury
Copy link
Contributor

@colesbury colesbury commented Mar 11, 2026

Add special cases for classmethod and staticmethod descriptors in _PyObject_GetMethodStackRef() to avoid calling tp_descr_get, which avoids reference count contention on the bound method and underlying callable. This improves scaling when calling classmethods and staticmethods from multiple threads.

Also refactor method_vectorcall in classobject.c into a new _PyObject_VectorcallPrepend() helper so that it can be used by PyObject_VectorcallMethod as well.

…eaded build

Add special cases for classmethod and staticmethod descriptors in
_PyObject_GetMethodStackRef() to avoid calling tp_descr_get, which
avoids reference count contention on the bound method and underlying
callable. This improves scaling when calling classmethods and
staticmethods from multiple threads.

Refactor method_vectorcall in classobject.c into a new
_PyObject_VectorcallPrepend() helper so that it can be used by
by PyObject_VectorcallMethod as well.
@colesbury colesbury force-pushed the gh-145779-classmethod-staticmethod-scaling branch from 70b0a53 to d86950f Compare March 11, 2026 14:52
@colesbury colesbury marked this pull request as ready for review March 11, 2026 15:46
@colesbury colesbury requested a review from mpage March 11, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant