STINNER Victor added the comment:

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.

----------
Added file: http://bugs.python.org/file42550/call_stack-2.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26814>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to