[Python-checkins] [3.10] gh-94841: Ensure arena_map_get() is inlined in PyObject_Free() (GH-94842)

nascheme webhook-mailer at python.org
Thu Jul 14 20:26:48 EDT 2022


https://github.com/python/cpython/commit/5d26f855213a4b6e57311ccac2af87c8d85f3499
commit: 5d26f855213a4b6e57311ccac2af87c8d85f3499
branch: 3.10
author: Neil Schemenauer <nas-github at arctrix.com>
committer: nascheme <nas-github at arctrix.com>
date: 2022-07-14T17:26:40-07:00
summary:

[3.10] gh-94841: Ensure arena_map_get() is inlined in PyObject_Free() (GH-94842)

Need to define ALWAYS_INLINE macro for 3.10.

Co-authored-by: neonene <53406459+neonene at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Build/2022-07-14-02-45-44.gh-issue-94841.lLRTdf.rst
M Objects/obmalloc.c

diff --git a/Misc/NEWS.d/next/Build/2022-07-14-02-45-44.gh-issue-94841.lLRTdf.rst b/Misc/NEWS.d/next/Build/2022-07-14-02-45-44.gh-issue-94841.lLRTdf.rst
new file mode 100644
index 0000000000000..f7ad4f88a51db
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2022-07-14-02-45-44.gh-issue-94841.lLRTdf.rst
@@ -0,0 +1 @@
+Fix the possible performance regression of :c:func:`PyObject_Free` compiled with MSVC version 1932.
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 615703a963ede..ed8dd5a5042d5 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -1397,9 +1397,19 @@ static int arena_map_bot_count;
 static arena_map_bot_t arena_map_root;
 #endif
 
+#if defined(Py_DEBUG)
+#  define ALWAYS_INLINE
+#elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
+#  define ALWAYS_INLINE __attribute__((always_inline))
+#elif defined(_MSC_VER)
+#  define ALWAYS_INLINE __forceinline
+#else
+#  define ALWAYS_INLINE
+#endif
+
 /* Return a pointer to a bottom tree node, return NULL if it doesn't exist or
  * it cannot be created */
-static arena_map_bot_t *
+static ALWAYS_INLINE arena_map_bot_t *
 arena_map_get(block *p, int create)
 {
 #ifdef USE_INTERIOR_NODES



More information about the Python-checkins mailing list