From: Victor Stinner <victor.stinner@gmail.com>
Date: Tue, 15 Nov 2016 14:13:40 +0000 (+0100)
Subject: Issue #28618: Mark dict lookup functions as hot
X-Git-Tag: v3.7.0a1~1984
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7a8f67411f45d26910c71603fe5a567f1dd6605;p=python

Issue #28618: Mark dict lookup functions as hot

It's common to see these functions in the top 3 of "perf report".
---

diff --git a/Include/pyport.h b/Include/pyport.h
index b91fc7468a..f7a16b264b 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -498,7 +498,7 @@ extern "C" {
 #endif
 
 
-/* Py_HOT_FUNCTION
+/* _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
@@ -506,7 +506,7 @@ extern "C" {
  * locality.
  *
  * Usage:
- *    int Py_HOT_FUNCTION x() { return 3; }
+ *    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
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 290686b88f..320dff6dfc 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -683,7 +683,7 @@ the <dummy> value.
 For both, when the key isn't found a DKIX_EMPTY is returned. hashpos returns
 where the key index should be inserted.
 */
-static Py_ssize_t
+static Py_ssize_t _Py_HOT_FUNCTION
 lookdict(PyDictObject *mp, PyObject *key,
          Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos)
 {
@@ -798,7 +798,7 @@ top:
 }
 
 /* Specialized version for string-only keys */
-static Py_ssize_t
+static Py_ssize_t _Py_HOT_FUNCTION
 lookdict_unicode(PyDictObject *mp, PyObject *key,
                  Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos)
 {
@@ -873,7 +873,7 @@ lookdict_unicode(PyDictObject *mp, PyObject *key,
 
 /* Faster version of lookdict_unicode when it is known that no <dummy> 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)
@@ -941,7 +941,7 @@ lookdict_unicode_nodummy(PyDictObject *mp, PyObject *key,
  * Split tables only contain unicode keys and no dummy keys,
  * so algorithm is the same as lookdict_unicode_nodummy.
  */
-static Py_ssize_t
+static Py_ssize_t _Py_HOT_FUNCTION
 lookdict_split(PyDictObject *mp, PyObject *key,
                Py_hash_t hash, PyObject ***value_addr, Py_ssize_t *hashpos)
 {