[New-bugs-announce] [issue40974] possible optimization: SHRINK_STACK(n)

SHRINK_STACK report at bugs.python.org
Sun Jun 14 08:08:18 EDT 2020


New submission from SHRINK_STACK <cwadrcjhjlhpoiwdwp at awdrt.com>:

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

----------
messages: 371501
nosy: shrink_stack
priority: normal
severity: normal
status: open
title: possible optimization: SHRINK_STACK(n)

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40974>
_______________________________________


More information about the New-bugs-announce mailing list