call_method() now uses _PyObject_FastCall() · pythoncapi/cpython@434723f · GitHub
Skip to content

Commit 434723f

Browse files
committed
call_method() now uses _PyObject_FastCall()
Issue python#29233: Replace the inefficient _PyObject_VaCallFunctionObjArgs() with _PyObject_FastCall() in call_method() and call_maybe(). Only a few functions call call_method() and call it with a fixed number of arguments. Avoid the complex and expensive _PyObject_VaCallFunctionObjArgs() function, replace it with an array allocated on the stack with the exact number of argumlents. It reduces the stack consumption, bytes per call, before => after: test_python_call: 1168 => 1152 (-16 B) test_python_getitem: 1344 => 1008 (-336 B) test_python_iterator: 1568 => 1232 (-336 B) Remove the _PyObject_VaCallFunctionObjArgs() function which became useless. Rename it to object_vacall() and make it private.
1 parent dbdfece commit 434723f

3 files changed

Lines changed: 66 additions & 52 deletions

File tree

Include/abstract.h

Lines changed: 0 additions & 8 deletions

Objects/abstract.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,8 +2700,8 @@ _PyObject_CallMethodId_SizeT(PyObject *obj, _Py_Identifier *name,
27002700
return retval;
27012701
}
27022702

2703-
PyObject *
2704-
_PyObject_VaCallFunctionObjArgs(PyObject *callable, va_list vargs)
2703+
static PyObject *
2704+
object_vacall(PyObject *callable, va_list vargs)
27052705
{
27062706
PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
27072707
PyObject **stack;
@@ -2767,7 +2767,7 @@ PyObject_CallMethodObjArgs(PyObject *callable, PyObject *name, ...)
27672767
}
27682768

27692769
va_start(vargs, name);
2770-
result = _PyObject_VaCallFunctionObjArgs(callable, vargs);
2770+
result = object_vacall(callable, vargs);
27712771
va_end(vargs);
27722772

27732773
Py_DECREF(callable);
@@ -2791,7 +2791,7 @@ _PyObject_CallMethodIdObjArgs(PyObject *obj,
27912791
}
27922792

27932793
va_start(vargs, name);
2794-
result = _PyObject_VaCallFunctionObjArgs(callable, vargs);
2794+
result = object_vacall(callable, vargs);
27952795
va_end(vargs);
27962796

27972797
Py_DECREF(callable);
@@ -2805,7 +2805,7 @@ PyObject_CallFunctionObjArgs(PyObject *callable, ...)
28052805
PyObject *result;
28062806

28072807
va_start(vargs, callable);
2808-
result = _PyObject_VaCallFunctionObjArgs(callable, vargs);
2808+
result = object_vacall(callable, vargs);
28092809
va_end(vargs);
28102810

28112811
return result;

Objects/typeobject.c

Lines changed: 61 additions & 39 deletions

0 commit comments

Comments
 (0)