monomorphic
Describes a place in the code that always sees objects of one single shape, which lets TurboFan optimise it best.
In more detail
A function called only with objects built the same way, such as { x, y }, stays monomorphic. Its property reads can then be compiled into direct memory accesses.
Related terms
- hidden class — An internal record V8 keeps of an object's property names and their order, so it can find properties quickly.
- polymorphic and megamorphic — Describes code that sees objects of a few different shapes (polymorphic) or very many (megamorphic), which makes optimisation harder.
- inlining — An optimisation that copies a small function's body, or a property lookup, straight into the code that uses it, avoiding the cost of a call or a search.
Taught in
- V8 Engine & JIT Pipeline: Bytecode & Turbofan — Node.js Internals & Backend Services