Message287153
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. |
|
Date |
User |
Action |
Args |
2017-02-06 17:08:28 | vstinner | set | recipients:
+ vstinner, methane, serhiy.storchaka |
2017-02-06 17:08:27 | vstinner | set | messageid: <1486400907.96.0.983593243638.issue29465@psf.upfronthosting.co.za> |
2017-02-06 17:08:27 | vstinner | link | issue29465 messages |
2017-02-06 17:08:27 | vstinner | create | |
|