[Vm-dev] in-line method lookup caching of booleans

Ben Coman btc at openinworld.com
Fri Aug 3 02:28:54 UTC 2018


Just a brain twitch about something I'd like to understand better...

At http://www.mirandabanda.org/cogblog/2011/03/01/build-me-a-jit-as-fast-as-you-can/
it says... "[Monomorphic] inline caching depends on the fact that in
most programs at most send sites there is no polymorphism and that
most sends bind to *exactly_one* class of receiver over some usefully
long period of time. ... In Cog we implement inline caches in three
forms ... monomorphic inline cache ... closed polymorphic inline cache
... open polymorphic cache.  What’s nice is that while these sends are
increasingly expensive moving from monomorphic to megamorphic they are
also decreasingly common in roughly a 90%, 9% 0.9% ratio, at least for
typical Smalltalk programs"

First, I'm curious what is the relative performance of the three
different caches ?

Second, I'm curious how Booleans are dealt with.  Boolean handling
must be fairly common, and at the Image level these are two different
classes, which pushes out of the monomorphic inline cache, which may
be a significant impact on performance.

I started wondering if under the hood the VM could treat the two
booleans as one class and in the instance store "which-boolean" it
actually is.  Then for example the #ifTrue:ifFalse: method of each
class would be compiled into a single method conditioned at the start
on "which-boolean" as to which path is executed.  How feasible would
that be, and would it make much of a difference in performance of
booleans ?

Except then I realized that this situation is already bypassed by
common boolean methods being inlined by the compiler.  Still curious,
if there are quick answers to my questions.

cheers -ben


More information about the Vm-dev mailing list