]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-150942: Speed up frame local item collection (gh-151002)
authorOmkar Kabde <omkarkabde@gmail.com>
Sun, 7 Jun 2026 12:05:53 +0000 (17:35 +0530)
committerGitHub <noreply@github.com>
Sun, 7 Jun 2026 12:05:53 +0000 (21:05 +0900)
Misc/NEWS.d/next/Core_and_Builtins/2026-06-06-08-20-00.gh-issue-150942.Jk9pQr.rst [new file with mode: 0644]
Objects/frameobject.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-06-08-20-00.gh-issue-150942.Jk9pQr.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-06-08-20-00.gh-issue-150942.Jk9pQr.rst
new file mode 100644 (file)
index 0000000..9777b89
--- /dev/null
@@ -0,0 +1,3 @@
+Speed up frame local variable item collection by appending result pairs to the
+output list without an extra reference-count round-trip (using the internal
+reference-stealing list append helper). Patch by Omkar Kabde.
index f60cdb2dd1bf20d124524bf1946a7d856b759861..b19889d3034e7156b439e1e30d3314ccbe9dc1b9 100644 (file)
@@ -9,6 +9,7 @@
 #include "pycore_function.h"      // _PyFunction_FromConstructor()
 #include "pycore_genobject.h"     // _PyGen_GetGeneratorFromFrame()
 #include "pycore_interpframe.h"   // _PyFrame_GetLocalsArray()
+#include "pycore_list.h"          // _PyList_AppendTakeRef()
 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
 #include "pycore_object.h"        // _PyObject_GC_UNTRACK()
 #include "pycore_opcode_metadata.h" // _PyOpcode_Caches
@@ -636,9 +637,7 @@ framelocalsproxy_items(PyObject *self, PyObject *Py_UNUSED(ignored))
                 goto error;
             }
 
-            int rc = PyList_Append(items, pair);
-            Py_DECREF(pair);
-            if (rc < 0) {
+            if (_PyList_AppendTakeRef((PyListObject *)items, pair) < 0) {
                 goto error;
             }
         }
@@ -655,9 +654,7 @@ framelocalsproxy_items(PyObject *self, PyObject *Py_UNUSED(ignored))
                 goto error;
             }
 
-            int rc = PyList_Append(items, pair);
-            Py_DECREF(pair);
-            if (rc < 0) {
+            if (_PyList_AppendTakeRef((PyListObject *)items, pair) < 0) {
                 goto error;
             }
         }