-
Notifications
You must be signed in to change notification settings - Fork 53
Improve generated code for some cases #55
Copy link
Copy link
Closed
Description
I just noticed that the generated code for this fragment could be better.
def f():
x, y = 101, 102
The disassembly is:
2 0 LOAD_CONST 1 ((101, 102))
2 UNPACK_SEQUENCE 2
4 STORE_FAST 0 (x)
6 STORE_FAST 1 (y)
The UNPACK_SEQUENCE opcode is pretty complex, the code would probably run faster if we generated it like this:
LOAD_CONST 1 (101)
STORE_FAST 0 (x)
LOAD_CONST 2 (102)
STORE_FAST 2 (y)
Another example:
def f(a, b):
x, y = a, b
Disassembled:
2 0 LOAD_FAST 0 (a)
2 LOAD_FAST 1 (b)
4 ROT_TWO
6 STORE_FAST 2 (x)
8 STORE_FAST 3 (y)
Why not
LOAD_FAST 0 (a)
STORE_FAST 2(x)
LOAD_FAST 1 (b)
STORE_FAST 3 (y)
?
That saves an opcode and a stack level. You'd have to reason about aliases, but for fast locals that's pretty simple, and threads can't interfere.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels