gh-151157: Speed up PyObject_CallMethod via _PyObject_GetMethod#151158
Open
eendebakpt wants to merge 1 commit into
Open
gh-151157: Speed up PyObject_CallMethod via _PyObject_GetMethod#151158eendebakpt wants to merge 1 commit into
eendebakpt wants to merge 1 commit into
Conversation
PyObject_CallMethod (and _PyObject_CallMethod, PyEval_CallMethod, _PyObject_CallMethodId and the _SizeT variant) resolved the method with PyObject_GetAttr, which builds a temporary bound-method object on every call, then called it. Resolve the method with _PyObject_GetMethod instead (the same lookup the interpreter uses for obj.name(...)) and call it directly via _PyObject_VectorcallPrepend, skipping the bound-method allocation. Behaviour is unchanged: same attribute semantics, same "attribute of type ... is not callable" error, and the historical PyObject_CallMethod(o, m, "O", tuple) -> o.m(*tuple) unpacking. The shared helper callmethod() and _PyObject_CallMethodFormat() are no longer needed: their only caller (traceback.c) now uses PyObject_CallFunction, so both are removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.