[Python-Dev] Micro-benchmarks for PEP 580 (original) (raw)

INADA Naoki songofacandy at gmail.com
Tue Jul 10 08:59:28 EDT 2018


On Tue, Jul 10, 2018 at 8:55 PM Jeroen Demeyer <J.Demeyer at ugent.be> wrote:

OK, I tried with --duplicate 200 and you can see the results at https://gist.github.com/jdemeyer/f0d63be8f30dc34cc989cd11d43df248 In short, the timings with and without PEP 580 are roughly the same (which is to be expected). Interestingly, a small but significant improvement can be seen when calling unbound methods. The real improvement comes from supporting a new calling protocol: formerly custom classes could only implement tpcall, but now they can use FASTCALL just like built-in functions/methods. For this, there is an improvement of roughly a factor 1.2 for calls without arguments, 1.6 for calls with positional arguments and 2.8 for calls with keywords.

We know it when we introduced FASTCALL.

What I want know is "how often" tp_call in custom type is called in real application. Does it boost real application performance significantly? 5%? 10%?

If it's not significant enough, I want to wait make FASTCALL public until more evolutionary optimization happened. There are some remaining possible optimizations.

For example, let's assume cfunction like this:

static PyObject* myfunc_impl(PyObject *self, Py_ssize_t i) { ... }

static PyObject* myfunc(PyObject *self, PyObject *arg) { Py_ssize_t i; if (!PyArg_Parse(arg, "n;myfunc", &i)) { return NULL; } return myfunc_impl(self, i); }

Then, the function is called from another C extension like this:

PyObject_CallFunction(func, "n", 42);

Currently, we create temporary long object for passing argument. If there is protocol for exposeing format used by PyArg_Parse*, we can bypass temporal Python object and call myfunc_impl directly.

I think optimization like this idea can boost application performance using Cython heavily. But in Python and stdlib, there are no enough "call C function from C function" scenarios, compared with Cython based applications. We really need help from Cython world for this area.

Regards,

INADA Naoki <songofacandy at gmail.com>



More information about the Python-Dev mailing list