[Python-Dev] Can LOAD_GLOBAL be optimized to a simple array lookup?

Brett Cannon brett at python.org
Thu Aug 24 00:28:55 CEST 2006


On 8/23/06, K.S.Sreeram <sreeram at tachyontech.net> wrote:
>
> Hi all,
>
> I noticed in Python/ceval.c that LOAD_GLOBAL uses a dictionary lookup,
> and was wondering if that can be optimized to a simple array lookup.


No, not as the language  stands now.

If i'm right there are 3 kinds of name lookups: locals, outer
> scopes(closures), and globals. (not counting attribute lookup). Locals
> are identified by, either the presence of assignments, or their presence
> in the arg list. So all name lookups can be classified into the 3 types
> at compile/load time.
>
> Since we know, at load time, which names are global.. Can't we simply
> build a global name table and replace LOAD_GLOBALs with a lookup at the
> corresponding index into the global name table?


But we don't know statically what the globals will be.  You can import a
module and put something in its global namespace externally.  That is done
after load time or compile time.

-Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20060823/0533d23a/attachment.htm 


More information about the Python-Dev mailing list