This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author shrink_stack
Recipients shrink_stack
Date 2020-06-14.12:08:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592136498.04.0.523354391069.issue40974@roundup.psfhosted.org>
In-reply-to
Content
context managers and except blocks generates multiple POP_TOPS constantly and maybe other cases which might lead generation of multiple POP_TOPS. A SHRINK_STACK(n) opcode would make things better (improvement on pyc size, less opcodes = faster evaluation). 

A possible patch:

(to peephole.c)
+
+            case POP_TOP:
+                h = i + 1;
+                while (h < codelen && _Py_OPCODE(codestr[h]) == POP_TOP) {
+                    h++;
+                }
+                if (h > i + 1) {
+                    codestr[i] = PACKOPARG(SHRINK_STACK, h - i);
+                    fill_nops(codestr, i + 1, h);
+                    nexti = h;
+                }
+                break;


(to ceval.c)
 
+        case TARGET(SHRINK_STACK): {
+            for (int i = 0; i < oparg; i++) {
+                PyObject *value = POP();
+                Py_DECREF(value);
+            }
+            FAST_DISPATCH();
+        }
+

and some other minor things for opcode.py and magic number
History
Date User Action Args
2020-06-14 12:08:18shrink_stacksetrecipients: + shrink_stack
2020-06-14 12:08:18shrink_stacksetmessageid: <1592136498.04.0.523354391069.issue40974@roundup.psfhosted.org>
2020-06-14 12:08:18shrink_stacklinkissue40974 messages
2020-06-14 12:08:17shrink_stackcreate