incremental algorithms for dispatching in dynamically typed languages
A fundamental problem in the implementation of object-oriented languages is that of a frugal dispatching data structure , i.e., support for quick response to dispatching queries combined with compact representation of the type hierarchy and the method families. Previous theoretical algorithms tend to be impractical due to their complexity and large hidden constant. In contrast, successful practical heuristics, including Vitek and Horspool's compact dispatch tables (CT) [16] designed for dynamically typed languages, lack theoretical support. In subjecting CT to theoretical analysis, we are not only able to improve and generalize it, but also provide the first non-trivial bounds on the performance of such a heuristic.Let n , m l denote the total number of types, messages, and different method implementations, respectively. Then, the dispatching matrix, whose size is nm , can be compressed by a factor of at most ? ? ( nm )/ l . Our main variant to CT achieves a compression factor of  ??. More generally, we describe a sequence of algorithms CT 1 , CT 2 , CT 3 ,..., where CT d achieves compression by a factor of (at least) 1 over d ? 11/ d , while using d memory dereferencing operations during dispatch. This tradeoff represents the first bounds on the compression ratio of constant-time dispatching algorithms.A generalization of these algorithms to a multiple-inheritance setting, increases the space by a factor of ? 1-1/ d , where ? is a metric of the complexity of the topology of the inheritance hierarchy, which (as indicated by our measurements) is typically small. The most important generalization is an incremental variant of the CT d scheme for a single-inheritance setting. This variant uses at most twice the space of CT d , and its time of inserting a new type into the hierarchy is optimal. We therefore obtain algorithms for efficient management of dispatching in dynamic-typing, dynamic-loading languages, such as Smalltalk and even the Java invokeinterface instruction.
incremental dispatch ct hierarchy message dynamic-typing