Re: [Python-Dev] Non-string keys in namespace dicts
PJE wrote:
Isn't the simplest way to cache attribute lookups to just have a cache dictionary in the type, and update that dictionary whenever a change is made to a superclass? That's essentially how __slotted__ attribute changes on base classes work now, isn't it?
Neil Toronto wrote:
The nice thing about caching pointers to dict entries is that they don't change as often as values do.
Is this really true for namespaces? I was thinking that the typical namespace usage is a bunch of inserts (possibly with lookups mixed in), followed by never changing it again until it is deallocated.
There are fewer ways to invalidate an entry pointer: inserting set, resize, clear, and delete.
I'm not sure how to resize without an inserting set. I'm not sure I've ever seen clear on a namespace. (I have seen it on regular dicts being used as a namespace, such as tcl config options.) I have seen deletes (deleting a temp name) and non-inserting sets ... but they're both rare enough that letting them force the slow path might be a good trade, if the optimization is otherwise simpler.
Rare updating also means it's okay to invalidate the entire cache rather than single entries
Changing __bases__ seems to do that already. (See http://svn.python.org/view/python/trunk/Objects/typeobject.c?rev=59106&view=markup functions like update_subclasses.) So I think an alternate version PJE's question would be: Why not just extend that existing mechanism to work on non-slot, non-method attributes? -jJ
participants (1)
-
Jim Jewett