how many places are optimized in Python's bytecode(version 2.5)

大兔子大兔子 提交于 2019-12-13 17:17:29

问题


Can anyone tell me how many places there are optimized in Python's bytecode? I was trying to de-compile Python's bytecode these days,but I found that in Python's version 2.5 there are a lot of optimization.For example: to this code

a,b,c=([],[],[])#build list

the non-optimized bytecode before version2.5 is like that:

BUILD_LIST_0
BUILD_LIST_0
BUILD_LIST_0
BUILD_LIST_4
UNPACK_LIST_
STORE_NAME 'a'
STORE_NAME 'b'
STORE_NAME 'c'

In the version2.5,the optimized bytecode is like this:

BUILD_LIST_0
BUILD_LIST_0
BUILD_LIST_0
ROT_THREE
ROT_TWO
STORE_FAST 'a'
STORE_FAST 'b'
STORE_FAST 'c'

This is only one example,but there are many other places may be optimized. So,does anybode know is there some documentation to clarify these optimization or tell me in which way I can find all of them?


回答1:


The Python/peephole.c source file is where basically all such optimizations are performed -- the link I gave is to the current version (2.6 or better), because I'm having trouble getting to the dynamic source browser here, but once it works again it's easy to see specific versions such as the one that was extant for (say) 2.5.2 or whatever other specific version you need this information for.




回答2:


I don't think there's any documentation per se, but there's the C code for the Python interpreter. You can find several different versions of it here.



来源:https://stackoverflow.com/questions/1010914/how-many-places-are-optimized-in-pythons-bytecodeversion-2-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!