This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients larry, rhettinger, serhiy.storchaka, vstinner, yselivanov
Date 2016-04-21.10:42:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
call_stack-2.patch: A little bit more complete patch, it adds a tp_call_stack field to PyTypeObject an use it in _PyObject_CallStack().

Updated microbenchmark on Python 3.6, best of 3 runs:

./python -m timeit -r 11 -s "from collections import namedtuple as n; a = n('n', 'a b c')(1, 2, 3)" -- "a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a; a.a"

* Python 3.6 unpatched: 0.968 usec
* call_stack.patch: 1.27 usec
* Python 3.6 with property_descr_get() of Python 3.4: 1.32 usec
* call_stack-2.patch: 0.664 usec

call_stack-2.patch makes this micro-benchmark 31% faster, not bad! It also makes calls to C functions almost 2x as fast if you replace current unoptimized calls with _PyObject_CallStack()!!

IHMO we should continue to experiment, making function calls 2x faster is worth it ;-)

Serhiy: "See also issue23507. May be your function help to optimize filter(), map(), sorted()?"

IMHO the API is generic enough to be usable in a lot of cases.

Serhiy: "Is there any use of this function with keyword arguments?"

Calling functions with keywords is probably the least common case for function calls in C code. But I would like to provide a fast function to call with keywords. Maybe we need two functions just to make the API cleaner? The difference would just be that "int k" would be omitted?

I proposed an API (PyObject **stack, int na, int nk) based on the current code in Python/ceval.c. I'm not sure that it's the best API ever :-)

In fact, there is already PyObject_CallFunctionObjArgs() which can be modified to reuse internally _PyObject_CallStack(), and its API is maybe more convenient than my proposed API.
Date User Action Args
2016-04-21 10:42:28vstinnersetrecipients: + vstinner, rhettinger, larry, serhiy.storchaka, yselivanov
2016-04-21 10:42:27vstinnersetmessageid: <>
2016-04-21 10:42:27vstinnerlinkissue26814 messages
2016-04-21 10:42:27vstinnercreate