New submission from SHRINK_STACK <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue40974>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com