You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Modify PyObject_CallFunction() to use fast call internally #73101
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2016-12-09.16:28:57.063>created_at=<Date2016-12-09.01:07:34.083>labels= ['3.7', 'performance']
title='Modify PyObject_CallFunction() to use fast call internally'updated_at=<Date2016-12-27.15:59:28.462>user='https://github.com/vstinner'
This issue tracks changes to support the "fast call" calling convention in functions:
PyObject_CallFunctionObjArgs()
PyObject_CallMethodObjArgs()
_PyObject_CallMethodIdObjArgs()
A "stack" of Python objects is created to pass arguments to _PyObject_FastCall(). The goal is to avoid the creation of a temporary tuple to call functions.
The patch serie changes slots (typeobject.c), so calling Python slots from Python should avoid completely the creation of temporary tuples to pass parameters.
Microbenchmark on a simple class with an __int__() method, call int(o):
Activity
vstinner commentedon Dec 9, 2016
This issue tracks changes to support the "fast call" calling convention in functions:
A "stack" of Python objects is created to pass arguments to _PyObject_FastCall(). The goal is to avoid the creation of a temporary tuple to call functions.
The patch serie changes slots (typeobject.c), so calling Python slots from Python should avoid completely the creation of temporary tuples to pass parameters.
Microbenchmark on a simple class with an __int__() method, call int(o):
int(o): Median +- std dev: [ref] 239 ns +- 13 ns -> [patch] 219 ns +- 14 ns: 1.10x faster (-9%)
Microbenchmark on a simple class with an __getitem__() method, call o[100]:
o[100]: Median +- std dev: [ref] 211 ns +- 11 ns -> [patch] 172 ns +- 11 ns: 1.23x faster (-19%)
Comparison between Python 2.7, 3.5, 3.7 and 3.7+patch, 3.5 is used as the reference:
======
Median +- std dev: [3.5] 271 ns +- 15 ns -> [3.7] 239 ns +- 13 ns: 1.13x faster (-12%)
Median +- std dev: [3.5] 271 ns +- 15 ns -> [patch] 219 ns +- 14 ns: 1.24x faster (-19%)
Median +- std dev: [3.5] 271 ns +- 15 ns -> [2.7] 401 ns +- 21 ns: 1.48x slower (+48%)
o[100]
======
Median +- std dev: [3.5] 206 ns +- 5 ns -> [3.7] 211 ns +- 11 ns: 1.02x slower (+2%)
Not significant!
Median +- std dev: [3.5] 206 ns +- 5 ns -> [patch] 172 ns +- 11 ns: 1.20x faster (-17%)
Median +- std dev: [3.5] 206 ns +- 5 ns -> [2.7] 254 ns +- 15 ns: 1.23x slower (+23%)
vstinner commentedon Dec 9, 2016
bench_slots.py: microbenchmark on __int__ and __getitem__ slots.
python-dev commentedon Dec 9, 2016
New changeset b771cf37714b by Victor Stinner in branch 'default':
Add _PyObject_FastCallVa() helper
https://hg.python.org/cpython/rev/b771cf37714b
New changeset 455169e87bb3 by Victor Stinner in branch 'default':
Add _PyObject_CallFunctionVa() helper
https://hg.python.org/cpython/rev/455169e87bb3
New changeset dd0d162593c5 by Victor Stinner in branch 'default':
modsupport: replace int with Py_ssize_t
https://hg.python.org/cpython/rev/dd0d162593c5
New changeset 69d5dcf31f4a by Victor Stinner in branch 'default':
modsupport: replace int with Py_ssize_t
https://hg.python.org/cpython/rev/69d5dcf31f4a
New changeset c1414b182232 by Victor Stinner in branch 'default':
Add _Py_VaBuildStack() function
https://hg.python.org/cpython/rev/c1414b182232
New changeset 69948a157507 by Victor Stinner in branch 'default':
_PyObject_CallFunctionVa() uses fast call
https://hg.python.org/cpython/rev/69948a157507
New changeset b9eb35435178 by Victor Stinner in branch 'default':
Don't parenthesis in _PyObject_CallMethodId() format
https://hg.python.org/cpython/rev/b9eb35435178
New changeset 67302e6caa29 by Victor Stinner in branch 'default':
Use _PyObject_CallMethodIdObjArgs()
https://hg.python.org/cpython/rev/67302e6caa29
New changeset 032cbdb596fe by Victor Stinner in branch 'default':
build_struct_time() uses Py_BuildValue()
https://hg.python.org/cpython/rev/032cbdb596fe
New changeset 49a7fdc0d40a by Victor Stinner in branch 'default':
time_strptime() uses PyObject_Call()
https://hg.python.org/cpython/rev/49a7fdc0d40a
New changeset 6e748eb79038 by Victor Stinner in branch 'default':
Add _PyObject_VaCallFunctionObjArgs() private function
https://hg.python.org/cpython/rev/6e748eb79038
New changeset adcd9131b7c6 by Victor Stinner in branch 'default':
Use _PyObject_FastCallVa() in type slots
https://hg.python.org/cpython/rev/adcd9131b7c6
python-dev commentedon Dec 9, 2016
New changeset 39bed12135c1 by Victor Stinner in branch 'default':
Issue bpo-28915: Use _PyObject_CallNoArg()
https://hg.python.org/cpython/rev/39bed12135c1
New changeset b29c719d5992 by Victor Stinner in branch 'default':
Use _PyObject_CallMethodIdObjArgs() in _asyncio
https://hg.python.org/cpython/rev/b29c719d5992
python-dev commentedon Dec 9, 2016
New changeset 807688539b56 by Victor Stinner in branch 'default':
Fix refleak introduced in change 032cbdb596fe
https://hg.python.org/cpython/rev/807688539b56
New changeset ceb22b8f6d32 by Victor Stinner in branch 'default':
Use _PyObject_CallMethodIdObjArgs() in _ctypes
https://hg.python.org/cpython/rev/ceb22b8f6d32
New changeset ef05cc5cc651 by Victor Stinner in branch 'default':
Use _PyObject_CallMethodIdObjArgs() in _elementtree
https://hg.python.org/cpython/rev/ef05cc5cc651
New changeset 5b41b92a7ccf by Victor Stinner in branch 'default':
Use _PyObject_CallMethodIdObjArgs() in _datetime
https://hg.python.org/cpython/rev/5b41b92a7ccf
New changeset 434e76e0ee17 by Victor Stinner in branch 'default':
Use _PyObject_CallMethodIdObjArgs() in _io
https://hg.python.org/cpython/rev/434e76e0ee17
New changeset 4545a2293e01 by Victor Stinner in branch 'default':
Use _PyObject_CallMethodIdObjArgs()
https://hg.python.org/cpython/rev/4545a2293e01
New changeset 4321f833a4e0 by Victor Stinner in branch 'default':
Use PyObject_CallFunctionObjArgs()
https://hg.python.org/cpython/rev/4321f833a4e0
vstinner commentedon Dec 9, 2016
The main feature was implemented, so I close the issue.
Enjoy faster slots! (Many other less important functions are also faster.)
python-dev commentedon Dec 15, 2016
New changeset bec846dd92e8 by Victor Stinner in branch 'default':
Fix _PyObject_CallFunctionVa(), use the small stack
https://hg.python.org/cpython/rev/bec846dd92e8
python-dev commentedon Dec 27, 2016
New changeset fa9933bf4ea0 by Serhiy Storchaka in branch 'default':
Issue bpo-28915: Exclude _Py_VaBuildStack from the limited API.
https://hg.python.org/cpython/rev/fa9933bf4ea0