This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients methane, serhiy.storchaka, vstinner
Date 2017-02-06.17:08:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1486400907.96.0.983593243638.issue29465@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-02-06 17:08:28vstinnersetrecipients: + vstinner, methane, serhiy.storchaka
2017-02-06 17:08:27vstinnersetmessageid: <1486400907.96.0.983593243638.issue29465@psf.upfronthosting.co.za>
2017-02-06 17:08:27vstinnerlinkissue29465 messages
2017-02-06 17:08:27vstinnercreate