summaryrefslogtreecommitdiffstats
path: root/Include/pyport.h
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-11-11 01:13:35 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-11-11 01:13:35 (GMT)
commitc6944e7edcacc8960170719623c325aefaf23cac (patch)
treeba703132b9c442a61873cd6644b652641978fcf0 /Include/pyport.h
parent0cae609847cccd78d3a960a70782c7b7ee891e3e (diff)
downloadcpython-c6944e7edcacc8960170719623c325aefaf23cac.zip
cpython-c6944e7edcacc8960170719623c325aefaf23cac.tar.gz
cpython-c6944e7edcacc8960170719623c325aefaf23cac.tar.bz2
Issue #28618: Make hot functions using __attribute__((hot))
When Python is not compiled with PGO, the performance of Python on call_simple and call_method microbenchmarks depend highly on the code placement. In the worst case, the performance slowdown can be up to 70%. The GCC __attribute__((hot)) attribute helps to keep hot code close to reduce the risk of such major slowdown. This attribute is ignored when Python is compiled with PGO. The following functions are considered as hot according to statistics collected by perf record/perf report: * _PyEval_EvalFrameDefault() * call_function() * _PyFunction_FastCall() * PyFrame_New() * frame_dealloc() * PyErr_Occurred()
Diffstat (limited to 'Include/pyport.h')
-rw-r--r--Include/pyport.h27
1 files changed, 25 insertions, 2 deletions
diff --git a/Include/pyport.h b/Include/pyport.h
index 20f3db7..b91fc74 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -490,13 +490,36 @@ extern "C" {
* typedef int T1 Py_DEPRECATED(2.4);
* extern int x() Py_DEPRECATED(2.5);
*/
-#if defined(__GNUC__) && ((__GNUC__ >= 4) || \
- (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
+#if defined(__GNUC__) \
+ && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
#else
#define Py_DEPRECATED(VERSION_UNUSED)
#endif
+
+/* Py_HOT_FUNCTION
+ * The hot attribute on a function is used to inform the compiler that the
+ * function is a hot spot of the compiled program. The function is optimized
+ * more aggressively and on many target it is placed into special subsection of
+ * the text section so all hot functions appears close together improving
+ * locality.
+ *
+ * Usage:
+ * int Py_HOT_FUNCTION x() { 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
+ * its time must use it. Use a profiler when running performance benchmark
+ * suite to find these functions.
+ */
+#if defined(__GNUC__) \
+ && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
+#define _Py_HOT_FUNCTION __attribute__((hot))
+#else
+#define _Py_HOT_FUNCTION
+#endif
+
/**************************************************************************
Prototypes that are missing from the standard include files on some systems
(and possibly only some versions of such systems.)