Blog
V8 hidden classes and inline caches: when JavaScript property access gets slow
V8 speeds up JavaScript property access with hidden classes and inline caches, but dynamic shape changes can deoptimize these optimizations, creating performance cliffs that are identifiable and avoidable.
Published by Tasadduq Burney
24 Jul 2025, 14:05 UTC
3 min73.1K views0

Why JavaScript property access can suddenly slow down
V8 makes reading an object property as fast as a memory offset lookup, but that speed depends on something you cannot see: the objects hidden class or Map.
Hidden classes (Maps) give objects a predictable shape
When V8 first adds a property to a plain object, it creates a hidden class Map that records where that property lives in memory. Objects that add the same property in the same order reuse the same Map, so V8 can skip the prototype chain entirely.
- The first property addition creates a Map ID.
- Objects with the same property sequence share that Map.
- V8 stores the property offset alongside the Map.
- Subsequent reads use the offset directly, no traversal needed.
d8 --trace-deopt -e '
const obj = {}
obj.foo = 1 Map A created IC records Map A plus offset of foo
obj.bar = 2 warms the IC at this access site
obj.baz = 3 changes the shape IC deoptimizes
%HasMap(obj) shows the new hidden class ID
'
Running this snippet with v8 --trace-deopt emits deoptimization events when obj.baz = 3 changes the objects hidden class forcing the runtime into the generic property access path.
In a real-world hot loop the same pattern adding a property after the IC has warmed up can cause the IC to transition from monomorphic to megamorphic and property read throughput can drop by several times.
Keeping shapes stable helps ICs stay monomorphic
If you know a property will be accessed frequently avoid adding or removing it inside the same loop. Pre-initialize objects with all needed fields and be cautious with spread operators or dynamic key generation that may produce different hidden classes across iterations.
Note V8 versions before 9.0 used a different inline cache implementation. If you need to support older Node.js versions or browsers that have not migrated to the current TurboFan IC strategy behavior may differ.
How to check your IC health
In the d8 shell %HasMap(obj) prints the hidden class ID letting you verify whether two objects share a shape. Pair this with v8 --trace-deopt to see deoptimization traces or use Node.js profiling tools like clinic to spot IC cache misses in flame graphs.
When ICs stay monomorphic or polymorphic your code benefits from constant-time property access. When they slide into megamorphy the fallback path is slower but knowing when and why it happens lets you restructure code to keep shapes predictable.0 replies
A thoughtful contribution can make all the difference. Be the first to share one.