Musing on PMD dispatch problems

Jecel Assumpcao Jr jecel at merlintec.com
Wed Aug 27 16:25:10 PDT 2003


I am still thinking about lookup order and dispatch implementations. In 
particular, I was wondering about adpating the traditional "message 
cache" from Smalltalk for this.

The idea is that you look up a combination of selector and type in the 
cache and it either returns a block which you execute or a "token" 
(another selector, really) which you use for further look ups.

Here is the "+" example again (where "mcache" is a function that takes a 
selector, a type, and a position as arguments) -

mcache("+",NumericArrayMD traits,1) = md1
mcache("md1",NumericArrayMD traits,2) = [ ... ]
mcache("+",UnitValue traits,1) = md2
mcache("md2",UnitValue traits,2) = [ ... ]
mcache("+",AbstractMatrix traits,1) = md3
mcache("md3",AbstractMatrix traits,2) = [ ... ]
mcache("md3",Magnitude traits,2) = [ ... ]
mcache("+",Magnitude traits,1) = md4
mcache("md4",AbstractMatrix traits,2) = [ ... ]
mcache("md4",PositiveEpsilon,2) = [ ... ]
mcache("md4",NegativeEpsilon,2) = [ ... ]
mcache("+",Fraction traits,1) = md5
mcache("md5",Integer traits,2) = [ ... ]
mcache("md5",Fraction traits,2) = [ ... ]
mcache("+",Integer traits,1) = md6
mcache("md6",Fraction traits,2) = [ ... ]
mcache("md6",Float traits,2) = [ ... ]
mcache("+",NumericMixin traits,1) = md7
mcache("md7",Number traits,2) = [ ... ]
mcache("md7",NumericMixin traits,2) = [ ... ]
mcache("+",Time Time traits,1) = md8
mcache("md8",Time Time traits,2) = [ ... ]
mcache("+",Time Duration traits,1) = md9
mcache("md9",Time Duration traits,2) = [ ... ]
mcache("+",Time Instant traits,1) = md10
mcache("md10",Time Duration traits,2) = [ ... ]
mcache("+",SpaceRequirement traits,1) = md11
mcache("md11",SpaceRequirement traits,2) = [ ... ]
mcache("md11",Magnitude traits,2) = [ ... ]
mcache("+",Float traits,1) = md12
mcache("md12",Integer traits,2) = [ ... ]
mcache("+",Complex traits,1) = md13
mcache("md13,Complex traits,2) = [ ... ]
mcache("+",SmallInteger traits,1) = md14
mcache("md14",SmallInteger traits,2) = [ ... ]
mcache("+",Rectangle traits,1) = md15
mcache("md15",Point2D traits,2) = [ ... ]

The cache would only hold a subset of these entries at any one time, and 
the actual "type" of be of the objects to which the message was sent 
instead of where the methods are found, so there would be an entry for 
"Integer" but not one for "Integer traits" as indicated above.

The idea is that the token holds all the information we need about the 
state of a partial look up. When the cache hits, a double dispatch only 
takes twice as long as a normal one and a triple dispatch (the largest 
I have seen so far in Slate) only three times as long.

Would this be practical way to do a simple implementation?

-- Jecel



More information about the Slate mailing list