Skip to content

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

Merged
colesbury merged 3 commits intopython:mainfrom
colesbury:gh-145779-classmethod-staticmethod-scaling
Mar 17, 2026
Merged

gh-145779: Improve classmethod/staticmethod scaling in free-threaded build#145826
colesbury merged 3 commits 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
Copy link
Contributor

@mpage mpage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@colesbury colesbury added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 17, 2026
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @colesbury for commit 3230ecc 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F145826%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 17, 2026
@colesbury colesbury merged commit e0f7c10 into python:main Mar 17, 2026
160 of 162 checks passed
@colesbury colesbury deleted the gh-145779-classmethod-staticmethod-scaling branch March 17, 2026 18:24
@miss-islington-app
Copy link

Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app
Copy link

Sorry, @colesbury, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker e0f7c1097e19b6f5c2399e19f283c9fb373c243f 3.14

colesbury added a commit to colesbury/cpython that referenced this pull request Mar 17, 2026
…eaded build (python#145826)

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.

(cherry picked from commit e0f7c10)
@bedevere-app
Copy link

bedevere-app bot commented Mar 17, 2026

GH-146088 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Mar 17, 2026
colesbury added a commit to colesbury/cpython that referenced this pull request Mar 17, 2026
…ree-threaded build (python#145826)

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.

(cherry picked from commit e0f7c10)
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.

3 participants