[Python-Dev] Re: opcode performance measurements
Skip Montanaro
skip@pobox.com
Thu, 31 Jan 2002 15:16:27 -0600
SP> cases. How does it handle things like
SP> import a.b
SP> use a.b.x
Jeremy> You're a smart guy, can you tell me? :-). Seriously, I haven't
Jeremy> gotten that far.
My stuff does handle this, as long as the first name is global. It just
gobbles up all LOAD_GLOBALS and any immediately following LOAD_ATTRs. For
instance, this trivial function:
def f():
return distutils.core.setup
compiles to:
0 LOAD_GLOBAL 0 (distutils)
3 LOAD_ATTR 1 (core)
6 LOAD_ATTR 2 (setup)
9 RETURN_VALUE
10 LOAD_CONST 0 (None)
13 RETURN_VALUE
My TrackGlobalOptimizer class currently transforms this to
0 SETUP_FINALLY 11 (to 14)
3 TRACK_GLOBAL 3 (distutils.core.setup, distutils.core.setup)
6 POP_BLOCK
7 LOAD_CONST 0 (None)
10 LOAD_FAST 0 (distutils.core.setup)
13 RETURN_VALUE
>> 14 UNTRACK_GLOBAL 3 (distutils.core.setup, distutils.core.setup)
17 END_FINALLY
18 LOAD_CONST 0 (None)
21 RETURN_VALUE
which is obviously not an improvement because distutils.core.setup is only
accessed once. As people make more use of packages, such multiple attribute
loads might become more common.
Skip