[Python-ideas] Fast global cacheless lookup

Neil Toronto ntoronto at cs.byu.edu
Thu Nov 22 17:42:14 CET 2007

Guido van Rossum wrote:
> Cool! Are you willing to show the code yet (bugs and all)?

Sure! I stayed up all night doing it and today is Thanksgiving, so I'll 
probably not get to it for a little while. (I know making a patch 
shouldn't take long, but I've never done it before.) Should I post the 
patch here or somewhere else?

> Some questions:
> - what's the space & time impact for a dict with no watchers?

I think it's almost negligible.

Space: There are four bytes extra on every dict for a pointer to the 
observer list. It may actually be zero or eight or more depending on 
alignment and malloc block size - I haven't looked.

Time: On dicts with no observers, dealloc, delitem, pop, popitem, clear, 
and resize pass through an "if (mp->ma_entryobs_list != NULL)". 
PyDict_New sets mp->ma_entryobs_list to NULL. Nothing else is affected.

> - does this do anything for builtins?

It does right now well enough to get them quickly, but setting or 
deleting them elsewhere won't show up yet in the frame. And it doesn't 
handle the case where __builtins__ is replaced. That'll take a little 
doing, but just mentally - it shouldn't affect performance much.

Anyway, that part will work properly when I'm done.

> - could this be made to work for instance variables?

If my brain were thinking in straight lines, maybe I'd come up with 
something. :) I've got this fuzzy idea that it just might work. The hard 
part may be distinguishing LOAD_ATTR applied to self from LOAD_ATTR 
applied to something else. Hmm...

Something to digest while I'm digesting the Real Other White Meat. :)

> - what about exec(src, ns) where ns is a mapping but not a dict?

Good question - I don't know, but I think it should work, at least as 
well as it did before. If there's no observer attached to a frame, it'll 
default to its previous behavior. Another hmm...

Thanks for the prompt reply.


P.S. By the way, I'm very pleased with how clean and workable the 
codebase is. I actually cheered at the lack of warnings. My wife 
probably thinks I'm nuts. :D

More information about the Python-ideas mailing list