[Python-Dev] Re: opcode performance measurements (original) (raw)

jepler@unpythonic.dhs.org jepler@unpythonic.dhs.org
Thu, 31 Jan 2002 16:54:52 -0600


On Thu, Jan 31, 2002 at 06:02:17AM -0500, Jeremy Hylton wrote:

JE> can f not optimize the load of the global g into a JE> LOADFASTGLOBAL?

So you've got a module with two globals f() and g(). They're stored in slots 0 and 1 of the module globals array. When f() and g() are compiled, the symbol table for the module can note the location of f() and g() and that f() and g() contain references to globals. Instead of emitting LOADGLOBAL "f" in g(), you can emit LOADGLOBAL 0 ("f").

But isn't what happens in this module something like LOAD_CONST MAKE_FUNCTION STORE_GLOBAL 0 (f)

LOAD_CONST <code2>
MAKE_FUNCTION 
STORE_GLOBAL 1 (g)

so if you convert LOAD_GLOBAL into LOAD_FAST_GLOBAL when you MAKE_FUNCTION on code1, there is not yet a "g" in the dlict.

Are you populating the "names" part of the dlict as an earlier "pass" of module compilation, then? So the optimization doesn't apply if I create the globals from within a function? (Of course, in that case it would work if I set the attributes to 'None' in the module scope, right?): def make_fg(): global f, g def f(x): pass def g(x): pass

Jeff