[Python-checkins] cpython: Disable _PyStack_AsTuple() inlining

victor.stinner python-checkins at python.org
Tue Jan 10 19:28:03 EST 2017


https://hg.python.org/cpython/rev/6478e6d0476f
changeset:   106083:6478e6d0476f
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Jan 11 01:07:03 2017 +0100
summary:
  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)

files:
  Include/pyport.h   |  15 ++++++++++++++-
  Objects/abstract.c |   4 +++-
  2 files changed, 17 insertions(+), 2 deletions(-)


diff --git a/Include/pyport.h b/Include/pyport.h
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -507,7 +507,7 @@
  * locality.
  *
  * Usage:
- *    int _Py_HOT_FUNCTION x() { return 3; }
+ *    int _Py_HOT_FUNCTION x(void) { return 3; }
  *
  * Issue #28618: This attribute must not be abused, otherwise it can have a
  * negative effect on performance. Only the functions were Python spend most of
@@ -521,6 +521,19 @@
 #define _Py_HOT_FUNCTION
 #endif
 
+/* _Py_NO_INLINE
+ * Disable inlining on a function. For example, it helps to reduce the C stack
+ * consumption.
+ *
+ * Usage:
+ *    int _Py_NO_INLINE x(void) { return 3; }
+ */
+#if defined(__GNUC__) || defined(__clang__)
+#  define _Py_NO_INLINE __attribute__((noinline))
+#else
+#  define _Py_NO_INLINE
+#endif
+
 /**************************************************************************
 Prototypes that are missing from the standard include files on some systems
 (and possibly only some versions of such systems.)
diff --git a/Objects/abstract.c b/Objects/abstract.c
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2256,7 +2256,9 @@
     return _Py_CheckFunctionResult(callable, result, NULL);
 }
 
-PyObject*
+/* Issue #29234: Inlining _PyStack_AsTuple() into callers increases their
+   stack consumption, Disable inlining to optimize the stack consumption. */
+PyObject* _Py_NO_INLINE
 _PyStack_AsTuple(PyObject **stack, Py_ssize_t nargs)
 {
     PyObject *args;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list