Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smalltalk dynamic lookup optimization

In Smalltalk, looking up a method at run time can involve a large number of steps, since the method dictionary of a subclass does not contain methods in its superclass, and a pointer-chase is required to find the method. A optimization would be for each subclass to store all superclass methods in its method dictionary.
Question: How could this be done?

An obvious drawback is the space cost, but I'm just wondering how this can be done in Smalltalk? This is different from making a separate cache for recently invoked methods.

like image 522
icicle Avatar asked Dec 18 '22 16:12

icicle


1 Answers

There are so many ways to cache the results of a lookup. Just read some basic VMimplementation papers - start with the Green Book. You can even find t for free online - http://stephane.ducasse.free.fr/FreeBooks.html and look near the bottom for 'Bits of History, Words of Advice'. Plain interpreters can use a simple hash keyed cache. Translating VMs can get into inline caches, polymorphic inline caches, adaptive caching... no need whatsoever to d something as painful as C++ vtables which is pretty much what you were suggesting. We've had this covered for decades. It's solved.

like image 125
timrowledge Avatar answered Feb 08 '23 12:02

timrowledge