Skip to content

gh-151157: Speed up PyObject_CallMethod via _PyObject_GetMethod#151158

Open
eendebakpt wants to merge 1 commit into
python:mainfrom
eendebakpt:optimize-callmethod-vectorcall
Open

gh-151157: Speed up PyObject_CallMethod via _PyObject_GetMethod#151158
eendebakpt wants to merge 1 commit into
python:mainfrom
eendebakpt:optimize-callmethod-vectorcall

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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>
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