diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-02-09 21:53:47 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-02-09 21:53:47 (GMT) |
commit | 516b98161a0e88fde85145ead571e13394215f8c (patch) | |
tree | dc7fbc055b3ba42af0afd09c7c65632c3b62daf3 /Include/abstract.h | |
parent | c42c65574dbc2dc105e0cf1d0b2bffd5f236a849 (diff) | |
download | cpython-516b98161a0e88fde85145ead571e13394215f8c.zip cpython-516b98161a0e88fde85145ead571e13394215f8c.tar.gz cpython-516b98161a0e88fde85145ead571e13394215f8c.tar.bz2 |
Optimize slots: avoid temporary PyMethodObject
Issue #29507: Optimize slots calling Python methods. For Python methods, get
the unbound Python function and prepend arguments with self, rather than
calling the descriptor which creates a temporary PyMethodObject.
Add a new _PyObject_FastCall_Prepend() function used to call the unbound Python
method with self. It avoids the creation of a temporary tuple to pass
positional arguments.
Avoiding temporary PyMethodObject and avoiding temporary tuple makes Python
slots up to 1.46x faster. Microbenchmark on a __getitem__() method implemented
in Python:
Median +- std dev: 121 ns +- 5 ns -> 82.8 ns +- 1.0 ns: 1.46x faster (-31%)
Co-Authored-by: INADA Naoki <songofacandy@gmail.com>
Diffstat (limited to 'Include/abstract.h')
-rw-r--r-- | Include/abstract.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Include/abstract.h b/Include/abstract.h index 231e209..03e2f02 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -257,6 +257,12 @@ PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend( PyObject *args, PyObject *kwargs); +PyAPI_FUNC(PyObject *) _PyObject_FastCall_Prepend( + PyObject *callable, + PyObject *obj, + PyObject **args, + Py_ssize_t nargs); + PyAPI_FUNC(PyObject *) _Py_CheckFunctionResult(PyObject *callable, PyObject *result, const char *where); |