Message226547
The following example function compiles to bytecode which contains,
an unnecessary JUMP_FORWARD 0 instruction:
def func():
if a: pass
Actual:
dis.dis(func)
2 0 LOAD_GLOBAL 0 (a)
3 POP_JUMP_IF_FALSE 9
6 JUMP_FORWARD 0 (to 9)
>> 9 LOAD_CONST 0 (None)
12 RETURN_VALUE
Expected:
dis.dis(func)
2 0 LOAD_GLOBAL 0 (a)
3 POP_JUMP_IF_FALSE 6
>> 6 LOAD_CONST 0 (None)
9 RETURN_VALUE
The above JUMP_FORWARD instruction increases the code size and also has a negative performance effect.
I do not see any reason to have the extra NOP in the byte code in this case.
***
The attached patch removes this NOP generation from the code compilation part, so it will take effect by default.
I had a little trouble when the code compiled from ast,
because the If.orelse had a different content. (NULL vs. zero sizes asdl_seq)
* The generated Assembly code updated in dis unit test.
* The compilation test updated to test a real 'if' by using a variable in the condition. (The True and False is not a variable anymore) |
|
Date |
User |
Action |
Args |
2014-09-07 23:15:52 | Attila.Fazekas | set | recipients:
+ Attila.Fazekas |
2014-09-07 23:15:51 | Attila.Fazekas | set | messageid: <1410131751.3.0.286807905275.issue22358@psf.upfronthosting.co.za> |
2014-09-07 23:15:51 | Attila.Fazekas | link | issue22358 messages |
2014-09-07 23:15:51 | Attila.Fazekas | create | |
|