diff -r 87d76ce01217 Include/pyport.h --- a/Include/pyport.h Fri Nov 04 17:07:47 2016 -0400 +++ b/Include/pyport.h Sat Nov 05 01:07:42 2016 +0100 @@ -497,6 +497,24 @@ extern "C" { #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 } + */ +#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.) diff -r 87d76ce01217 Objects/dictobject.c --- a/Objects/dictobject.c Fri Nov 04 17:07:47 2016 -0400 +++ b/Objects/dictobject.c Sat Nov 05 01:07:42 2016 +0100 @@ -871,7 +871,7 @@ lookdict_unicode(PyDictObject *mp, PyObj /* Faster version of lookdict_unicode when it is known that no keys * will be present. */ -static Py_ssize_t +static Py_ssize_t Py_HOT_FUNCTION lookdict_unicode_nodummy(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos) diff -r 87d76ce01217 Objects/frameobject.c --- a/Objects/frameobject.c Fri Nov 04 17:07:47 2016 -0400 +++ b/Objects/frameobject.c Sat Nov 05 01:07:42 2016 +0100 @@ -409,7 +409,7 @@ static int numfree = 0; /* numbe /* max value for numfree */ #define PyFrame_MAXFREELIST 200 -static void +static void Py_HOT_FUNCTION frame_dealloc(PyFrameObject *f) { PyObject **p, **valuestack; @@ -605,7 +605,7 @@ int _PyFrame_Init() return 1; } -PyFrameObject * +PyFrameObject* Py_HOT_FUNCTION PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals, PyObject *locals) { diff -r 87d76ce01217 Python/ceval.c --- a/Python/ceval.c Fri Nov 04 17:07:47 2016 -0400 +++ b/Python/ceval.c Sat Nov 05 01:07:42 2016 +0100 @@ -718,7 +718,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int return tstate->interp->eval_frame(f, throwflag); } -PyObject * +PyObject* Py_HOT_FUNCTION _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) { #ifdef DXPAIRS @@ -4771,7 +4771,7 @@ if (tstate->use_tracing && tstate->c_pro x = call; \ } -static PyObject * +static PyObject* Py_HOT_FUNCTION call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames) { PyObject **pfunc = (*pp_stack) - oparg - 1; @@ -4844,7 +4844,7 @@ call_function(PyObject ***pp_stack, Py_s done before evaluating the frame. */ -static PyObject* +static PyObject* Py_HOT_FUNCTION _PyFunction_FastCall(PyCodeObject *co, PyObject **args, Py_ssize_t nargs, PyObject *globals) {