[Python-ideas] Fast global cacheless lookup

Neil Toronto ntoronto at cs.byu.edu
Fri Nov 23 09:42:51 CET 2007


Greg Ewing wrote:
> Neil Toronto wrote:
>> The hard 
>> part may be distinguishing LOAD_ATTR applied to self from LOAD_ATTR 
>> applied to something else.
> 
> Why would you *want* to distinguish that? A decent attribute
> lookup acceleration mechanism should work for attributes of
> any object, not just self. Think method calls, which are
> probably even more common than accesses to globals.

Now that's a durned good point. My cute little hack can be used anywhere 
you have a mostly-static dict (or at least one that grows infrequently) 
and a tuple of keys for which you want to repeatedly get or set values. 
As long as lookups start as tuple indexes (like indexes into co_names 
and such), things go fast.

I'm still a bit fuzzy about how it would be used with LOAD_ATTR. Let's 
restrict it to just accelerating self.<attr> lookups for now. The oparg 
to LOAD_ATTR and STORE_ATTR is the co_names index, so co_names is again 
the tuple of keys. But it seems like you'd need an adapter (see previous 
reply to Eyal for terminology) for each pair of (self, method). Is there 
a better way?

Neil



More information about the Python-ideas mailing list