V8 powers Chrome and Node.js. Understanding how it compiles and optimizes your code helps you write faster JavaScript.
The Pipeline
Ignition: The Interpreter
Ignition compiles JavaScript to bytecode quickly. This is the "fast startup" path. Code runs immediately but isn't highly optimized.
TurboFan: The Optimizing Compiler
When a function is called many times (becomes "hot"), TurboFan compiles it to optimized machine code. It makes assumptions based on observed types:
Hidden Classes
V8 creates hidden classes (shapes) for objects. Objects with the same property order share hidden classes, enabling fast property access.
Inline Caching
V8 caches the location of properties. If an object always has the same shape, property access is as fast as C++ struct access.
Optimization Tips
- Keep function argument types consistent
- Initialize all properties in constructors
- Don't delete properties — set to undefined instead
- Avoid changing object shapes after creation
- Use TypedArrays for numeric data (Float64Array, Int32Array)
- Small functions inline better — keep functions focused