[issue29465] Add _PyObject_FastCall() to reduce stack consumption

STINNER Victor report at bugs.python.org
Mon Feb 6 12:08:28 EST 2017


New submission from STINNER Victor:

While testing issue #29464 patch, I failed to see a major enhancement on the stack usage of fast calls without keyword arguments.

The problem is that functions like _PyObject_FastCallKeywords() and _PyObject_FastCallDict() still have to pass a NULL argument for kwargs/kwnames, and have code to handle keyword arguments.


Attached patch adds _PyObject_FastCall() to reduce the stack consumption. At the C level, keyword arguments are almost never used. For example, PyObject_CallFunctionObjArgs() is commonly used, whereas it only uses positional arguments.

The patch changes also _PyObject_FastCallKeywords() and _PyObject_FastCallDict() to move the "slow" path creating temporary tuple and dict in a subfunction which is not inlined. The slow path requires more stack memory.

Morecall, _PyObject_FastCallKeywords() and _PyObject_FastCallDict() are modified to call _PyObject_FastCall() if there is no keyword.

The patch might make function calls without keyword arguments faster, I didn't check.


Stack usage.

$ ./python -c 'import _testcapi, sys; sys.setrecursionlimit(10**5); n=1000; s=_testcapi.meth_fastcall_stacksize(n); print("%.1f B/call" % (s/n))'

* Reference: 832.8 B/call
* Patch: 656.6 B/call (-176.2 B)

I don't know why the stack usage is not an integer number of bytes?


Combined with the issue #29464 "Specialize FASTCALL for functions with positional-only parameters", the stack usage can be even more reduced by a few bytes.


See the issue #28870 for the previous work on reducing stack consumption.

----------
components: Interpreter Core
files: pyobject_fastcall.patch
keywords: patch
messages: 287153
nosy: haypo, inada.naoki, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Add _PyObject_FastCall() to reduce stack consumption
type: resource usage
versions: Python 3.7
Added file: http://bugs.python.org/file46545/pyobject_fastcall.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29465>
_______________________________________


More information about the Python-bugs-list mailing list