JavaScript Engine: V8 Internals
22 min read
V8JIT CompilationCall StackHeapIgnitionTurboFanHidden Classes
Inside the V8 JavaScript Engine
The Execution Pipeline
- Parser: Parses source code into an Abstract Syntax Tree (AST)
- Ignition (Interpreter): Converts AST to bytecode, starts executing immediately
- TurboFan (Optimizing Compiler): Compiles hot functions to optimized machine code
- Deoptimization: If assumptions violated (type changes), reverts to bytecode
Call Stack and Heap
- Call Stack: LIFO structure tracking function execution. Stack Overflow occurs at ~10,000 frames.
- Heap: Unstructured memory where objects and closures live. Managed by garbage collector.
Hidden Classes (Shapes)
V8 creates internal hidden classes for objects with the same structure, enabling fast property lookups. Objects created in different orders get different hidden classes.
Writing V8-Friendly Code
- Always pass the same types to a function (monomorphic)
- Initialize all properties in constructors
- Use undefined instead of delete (delete changes hidden class)
- Use TypedArrays for number-heavy work