https://github.com/python/cpython/commit/253904f75259b1f22c42b50ee942c6958cf1478f
commit: 253904f75259b1f22c42b50ee942c6958cf1478f
branch: main
author: Omkar Kabde <[email protected]>
committer: corona10 <[email protected]>
date: 2026-06-07T21:05:53+09:00
summary:

gh-150942: Speed up frame local item collection (gh-151002)

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-06-06-08-20-00.gh-issue-150942.Jk9pQr.rst
M 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
index 000000000000000..9777b8932271404
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-06-08-20-00.gh-issue-150942.Jk9pQr.rst
@@ -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.
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index f60cdb2dd1bf20d..b19889d3034e715 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -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;
             }
         }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to