Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b915bc3

Browse files
committed
Disable _PyStack_AsTuple() inlining
Issue #29234: Inlining _PyStack_AsTuple() into callers increases their stack consumption, Disable inlining to optimize the stack consumption. Add _Py_NO_INLINE: use __attribute__((noinline)) of GCC and Clang. It reduces the stack consumption, bytes per call, before => after: test_python_call: 1040 => 976 (-64 B) test_python_getitem: 976 => 912 (-64 B) test_python_iterator: 1120 => 1056 (-64 B) => total: 3136 => 2944 (- 192 B)
1 parent 415c510 commit b915bc3

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

Include/pyport.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ extern "C" {
507507
* locality.
508508
*
509509
* Usage:
510-
* int _Py_HOT_FUNCTION x() { return 3; }
510+
* int _Py_HOT_FUNCTION x(void) { return 3; }
511511
*
512512
* Issue #28618: This attribute must not be abused, otherwise it can have a
513513
* negative effect on performance. Only the functions were Python spend most of
@@ -521,6 +521,19 @@ extern "C" {
521521
#define _Py_HOT_FUNCTION
522522
#endif
523523

524+
/* _Py_NO_INLINE
525+
* Disable inlining on a function. For example, it helps to reduce the C stack
526+
* consumption.
527+
*
528+
* Usage:
529+
* int _Py_NO_INLINE x(void) { return 3; }
530+
*/
531+
#if defined(__GNUC__) || defined(__clang__)
532+
# define _Py_NO_INLINE __attribute__((noinline))
533+
#else
534+
# define _Py_NO_INLINE
535+
#endif
536+
524537
/**************************************************************************
525538
Prototypes that are missing from the standard include files on some systems
526539
(and possibly only some versions of such systems.)

Objects/abstract.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,9 @@ PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
22562256
return _Py_CheckFunctionResult(callable, result, NULL);
22572257
}
22582258

2259-
PyObject*
2259+
/* Issue #29234: Inlining _PyStack_AsTuple() into callers increases their
2260+
stack consumption, Disable inlining to optimize the stack consumption. */
2261+
PyObject* _Py_NO_INLINE
22602262
_PyStack_AsTuple(PyObject **stack, Py_ssize_t nargs)
22612263
{
22622264
PyObject *args;

0 commit comments

Comments
 (0)