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 Attila.Fazekas
Recipients Attila.Fazekas
Date 2014-09-07.23:15:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1410131751.3.0.286807905275.issue22358@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2014-09-07 23:15:52Attila.Fazekassetrecipients: + Attila.Fazekas
2014-09-07 23:15:51Attila.Fazekassetmessageid: <1410131751.3.0.286807905275.issue22358@psf.upfronthosting.co.za>
2014-09-07 23:15:51Attila.Fazekaslinkissue22358 messages
2014-09-07 23:15:51Attila.Fazekascreate