A property access can become slower without changing its source code. V8 speeds repeated lookups with an inline cache: it remembers where a property resides for a particular hidden class, then reuses that location when the next object has the same shape. section 5.10.2
The optimization depends on the shapes seen at one access site. One shape is monomorphic; two through four are polymorphic; more than four are megamorphic. Shape changes invalidate remembered locations, and repeated variation can force slower object handling. section 5.10.2
Use the state model to interpret both behavior and diagnostics:
- Monomorphic access sites see one object shape and provide the strongest specialization. section 5.10.2
- Polymorphic sites retain several shape-specific paths, with performance degrading as more shapes are added. section 5.10.2
- Megamorphic sites have seen more than four shapes and can lose the relevant optimizations. section 5.10.2
- Treat IC traces as runtime evidence rather than language semantics: Node.js exposes --log-ic and --trace-deopt, while tooling differs across runtimes. section 5.10.2 section 11.5
Watching one access site widen
For function readX(point) { return point.x; }, feed objects shaped with x plus a, b, c, d, e, and f. The access site moves from uninitialized to monomorphic, then polymorphic, and finally megamorphic. A Node.js 24 measurement reports 1.116 nanoseconds per load for one shape, 2.094 for four, and 5.414 for five. section 5.10.2
const shapes = [
{ x: 1, a: 0 }, { x: 2, b: 0 }, { x: 3, c: 0 },
{ x: 4, d: 0 }, { x: 5, e: 0 }, { x: 6, f: 0 },
];
let total = 0;
for (let limit = 1; limit <= shapes.length; limit++) {
for (let i = 0; i < limit * 2; i++) total += readX(shapes[i % limit]);
}Run the shape-variation loop to observe how repeated property loads expose IC state changes. section 5.10.2
