views:

150

answers:

2

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?

A: 

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.

Head Geek
+2  A: 

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.

Alex Martelli
But I can't find this file in Python 2.5
higer