New submission from STINNER Victor: Subset of the (almost) rejected issue #29259 (tp_fastcall), attached patch adds _PyMethod_FastCall() and uses it in call_method() of typeobject.c. The change avoids the creation of a temporary tuple for Python functions and METH_FASTCALL C functions.
Currently, call_method() calls method_call() which calls _PyObject_Call_Prepend(), and calling method_call() requires a tuple for positional arguments. Example of benchmark on __getitem__(): 1.3x faster (-22%). $ ./python -m perf timeit -s 'class C:' -s ' def __getitem__(self, index): return index' -s 'c=C()' 'c[0]' Median +- std dev: 130 ns +- 1 ns => 102 ns +- 1 ns See also the issue #29263 "Implement LOAD_METHOD/CALL_METHOD for C functions". ---------- components: Interpreter Core files: method_fastcall.patch keywords: patch messages: 287371 nosy: haypo, inada.naoki, serhiy.storchaka priority: normal severity: normal status: open title: Use FASTCALL in call_method() to avoid temporary tuple type: performance versions: Python 3.7 Added file: http://bugs.python.org/file46601/method_fastcall.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29507> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com