[Python-Dev] New calling convention to avoid temporarily tuples when calling functions

Victor Stinner victor.stinner at gmail.com
Mon Aug 8 19:31:48 EDT 2016


2016-08-09 0:40 GMT+02:00 Guido van Rossum <guido at python.org>:
> Hm, I agree that those tuples are probably expensive. I recall that
> IronPython boasted faster Python calls by doing something closer to the
> platform (in their case I'm guessing C# or the CLR :-).

To be honest, I didn't expect *any* speedup just by avoiding the
temporary tuples. The C structore of tuples is simple and the
allocation of tuples is already optimized by a free list. I still
don't understand how the cost of tuple creation/destruction can have
such "large" impact on performances.

The discussion with Larry was not really my first motivation to work
on FASTCALL.

I worked on this topic because CPython already uses some "hidden"
tuples to avoid the cost of the tuple creation/destruction in various
places, but using really ugly code and this ugly code caused crashes
and surprising behaviours...

https://bugs.python.org/issue26811 is a recent crash related to
property_descr_get() optimization, whereas the optimization was
already "fixed" once:
https://hg.python.org/cpython/rev/5dbf3d932a59/

The fix is just another hack on top of the existing hack. The issue
#26811 rewrote the optimization to avoid the crash using
_PyObject_GC_UNTRACK():
https://hg.python.org/cpython/rev/a98ef122d73d

I tried to make this "optimization" the standard way to call
functions, rather than a corner case, and avoid hacks like
PyTuple_SET_ITEM(args, 0, NULL) or _PyObject_GC_UNTRACK().

Victor


More information about the Python-Dev mailing list