Author vstinner
Recipients larry, rhettinger, serhiy.storchaka, vstinner, yselivanov
Date 2016-04-21.15:03:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1461250989.34.0.323446607853.issue26814@psf.upfronthosting.co.za>
In-reply-to
Content
Since early microbenchmarks are promising, I wrote a more complete implementations which tries to use the fast-path (avoid temporary tuple/dict) in all PyObject_Call*() functions.

The next step would be to add a METH_FASTCALL flag. IMHO adding such new flag requires to enhance Argument Clinic to be able to use it, at least when a function doesn't accept keyword parameters.

PyObject_CallFunction() & friends have a weird API: if call with the format string "O", the behaviour depends if the object parameter is a tuple or not. If it's a tuple, the tuple is unpacked. It's a little bit weird. I recall that it led to a bug in the implementation in generators in Python: issue #21209! Moreover, if the format string is "(...)", parenthesis are ignored. If you want to call a function with one argument which is a tuple, you have to write "((...))". It's a little bit weird, but we cannot change that without breaking the (Python) world :-)

call_stack-3.patch:

* I renamed the main function to _PyObject_FastCall()
* I added PyObject_CallNoArg(): call a function with no parameter
* I added Py_VaBuildStack() and _Py_VaBuildStack_SizeT() helpers for PyObject_Call*() functions using a format string
* I renamed the new slot to tp_fastcall

Nice change in the WITH_CLEANUP_START opcode (ceval.c):

-            /* XXX Not the fastest way to call it... */
-            res = PyObject_CallFunctionObjArgs(exit_func, exc, val, tb, NULL);

+            arg_stack[0] = exc;
+            arg_stack[1] = val;
+            arg_stack[2] = tb;
+            res = _PyObject_FastCall(exit_func, arg_stack, 3, 0);

I don't know if it's a common byetcode, nor if the change is really faster.
History
Date User Action Args
2016-04-21 15:03:10vstinnersetrecipients: + vstinner, rhettinger, larry, serhiy.storchaka, yselivanov
2016-04-21 15:03:09vstinnersetmessageid: <1461250989.34.0.323446607853.issue26814@psf.upfronthosting.co.za>
2016-04-21 15:03:09vstinnerlinkissue26814 messages
2016-04-21 15:03:08vstinnercreate