[Python-Dev] Accessing globals without dict lookup

Skip Montanaro skip@pobox.com
Sun, 10 Feb 2002 15:53:07 -0600


    Tim> If I'm reading this right, then in the normal case of resolving
    Tim> "len" in

    Tim> def mylen(s):
    Tim>     return len(s)

    ...

    Tim> Jeremy, can you do the same level of detail for your scheme?  Skip?

Yeah, it's

    TRACK_GLOBAL        'len'
    LOAD_FAST           <len>
    LOAD_FAST           <s>
    CALL_FUNCTION       1
    UNTRACK_GLOBAL      'len'
    RETURN_VALUE

or something similar.  (Stuff in <...> represent array indexes.)

My scheme makes update of my local copy of __builtins__.len the
responsibility of the guy who changes the global copy.  Most of the time
this never changes, so as the number of accesses to len increase, the
average time per lookup approaches that of a simple LOAD_FAST.

Skip