[Zope3-dev] N-Tuple Adapters

Shane Hathaway shane@zope.com
Tue, 03 Jun 2003 09:42:18 -0400


Phillip J. Eby wrote:
> At 11:44 PM 6/2/03 -0400, Shane Hathaway wrote:
> Because the adapter composition (and recursion) is done at declaration 
> time, rather than at retrieval time.  Whenever you register an adapter, 
> the registration is forwarded to all implied protocols immediately, so 
> long as the registration resulted in a shortened adapter path.  As soon 
> as a registration fails to shorten an adapter path, recursion stops.  At 
> that point, the network of adapter paths is up-to-date.  Each protocol 
> then knows exactly how to adapt anything that comes its way.  Average 
> lookup time is proportional to the MRO length of the incoming objects' 
> classes: one dictionary lookup occurs for each class in the MRO, until 
> an adapter path is found.  The adapter path is then simply invoked.

Ah, of course.  You made the adapter registry know about all interface 
implementations.  That gives you all sorts of optimization 
possibilities.  Like Steve, I considered caching as a way to speed up 
adapter lookup, but that introduces the need for some kind of cache 
invalidation.  Your way avoids the need for caching, making it appealing.

BTW I got my answer to the original questions from one of Steve's links: 
to speed up multiple dispatch, you use a decision tree.  Then speed 
becomes a matter of building efficient trees.  It seems like it could be 
complex but very fast.

Shane