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> LOAD_FAST_GLOBAL? > > 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 LOAD_GLOBAL "f" in g(), you can emit LOAD_GLOBAL 0 ("f"). But isn't what happens in this module something like LOAD_CONST <code1> 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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4