๐ Inside V8: How Chrome Executes JavaScript at Lightning Speed

๐ What is V8?
V8 is the JavaScript engine that powers Google Chrome and Node.js. It's written in C++ and is responsible for reading your JavaScript code and turning it into fast machine code that your computer can actually run.
But it doesn't do this all at once. V8 uses a multi-stage process to go from source code to machine code, making smart decisions along the way to balance startup time and performance.
๐งญ The V8 Journey โ Step by Step
Step | What it does | Why it matters |
1. Parser | Reads your code and builds an AST (Abstract Syntax Tree). | Helps V8 understand the structure of your code. |
2. Ignition (Interpreter) | Converts AST into bytecode and runs it immediately. | Fast startup! Your app begins working right away. |
3. Sparkplug (Baseline JIT) | Converts frequently run bytecode into rough machine code. | Runs faster than the interpreter, still quick to generate. |
4. Maglev (Mid-tier JIT) | A new fast-optimizing compiler that bridges the gap. | Compiles hot code faster than TurboFan with better speed. |
5. TurboFan (Optimizing JIT) | Compiles the hottest functions into super-optimized machine code. | Best performance, but takes longer to generate. |
6. Machine Code | Final native CPU instructions are now running directly. | Your JavaScript is now as fast as it can get! |
โ Summary
V8 uses a tiered approach:
Starts quickly (Ignition),
Speeds up gradually (Sparkplug, Maglev),
Ends in turbo mode (TurboFan).
Each step is a smart tradeoff between speed of compiling and speed of running. V8 constantly adjusts to how your code behaves in the real world.
Subscribe to my newsletter
Read articles from pushpesh kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
