Posts

Showing posts from January, 2026

[EN] Intepreter Optimization: Shapes and Inline Caches

Typical implementations of Javascript and other high-level languages don't store objects as hash tables. (although that is the mental model they expose to users) Instead, objects are stored as flat buffers, with a side field-to-offset table (usually called the "shape" or "dynamic type") that's shared by all the objects with the same shape. To avoid looking up the side table they also keep some space for an offset cache (usually called the "inline cache") right in the bytecode/syntax tree, next to any "field access" instruction. The cache is usually of size 1 or 2 and is only invalidated when an instruction is run on objects of different shapes. This technique is pretty ancient, coming originally from method lookup in Smalltalk. In my experiments, it gives 12x speedup for object field access.