STINNER Victor added the comment: I reworked abstract.c to prepare work for this issue:
* change 455169e87bb3: Add _PyObject_CallFunctionVa() helper * change 6e748eb79038: Add _PyObject_VaCallFunctionObjArgs() private function * change 71876e4abce4: Add _PY_FASTCALL_SMALL_STACK constant I wrote a function _testcapi to measure the consumption of the C code. I was surprised by the results: calling PyObject_CallFunctionObjArgs(func, arg1, arg2, NULL) consumes 560 bytes! I measured on a Python compiled in release mode. Attached less_stack.patch rewrites _PyObject_VaCallFunctionObjArgs(), it reduces the stack consumption from 560 bytes to 384 bytes (-176 bytes!). Changes: * Remove "va_list countva" variable: the va_list variable itself, va_copy(), etc. consume stack memory. First I tried to move code to a subfunction, it helps. With my patch, it's even simpler. * Reduce _PY_FASTCALL_SMALL_STACK from 5 to 3. Stack usage is not directly _PY_FASTCALL_SMALL_STACK*sizeof(PyObject*), it's much more, probably because of complex memory alignement rules. * Use Py_LOCAL_INLINE(). It seems like depending on the size of the object_vacall() function body, the function is inlined or not. If it's not inlined, the stack usage increases from 384 bytes to 544 bytes!? Use Py_LOCAL_INLINE() to force inlining. Effect of _PY_FASTCALL_SMALL_STACK: * 1: 368 bytes * 2: 384 bytes * 3: 384 bytes -- value chosen in my patch * 4: 400 bytes * 5: 416 bytes ---------- Added file: http://bugs.python.org/file45915/less_stack.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28870> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com