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

K.S.Sreeram sreeram at tachyontech.net
Wed Aug 23 23:22:55 CEST 2006

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.

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?

The module's dict object will need to be special so that whenever a name
gets 'set', the global name table should get updated.

Is this optimization possible or have i missed something?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
Url : http://mail.python.org/pipermail/python-dev/attachments/20060824/d936dba5/attachment.pgp 

More information about the Python-Dev mailing list