Compiler & Interpreter
Compiler & Interpreter
Section titled “Compiler & Interpreter”Introduction
Section titled “Introduction”Modern JavaScript engines use a JIT (Just-In-Time) compilation approach — they interpret code initially for fast startup and compile hot paths to machine code for performance.
Interpreter (Ignition)
Section titled “Interpreter (Ignition)”V8’s Ignition interpreter executes bytecode directly. It’s fast to start but slower than compiled code.
// Bytecode (Ignition)// LdaGlobal 'console' ; Load global// Star0 ; Store// LdaNamedProperty r0, 'log'// Star1// LdaSmi [42]// CallProperty1 r1, r0Compiler (TurboFan)
Section titled “Compiler (TurboFan)”TurboFan compiles frequently executed (“hot”) functions to highly optimized machine code.
flowchart TD A["Function starts"] B["Ignition interprets bytecode"] C["Is function hot?"] D["TurboFan compiles to machine code"] E["Execute optimized code"] F["Deoptimize on type change"]
A --> B B --> C C -->|No| B C -->|Yes| D D --> E E -->|"✅ Works"| E E -->|"❌ Type change"| F F --> BCompilation vs Interpretation
Section titled “Compilation vs Interpretation”| Feature | Interpreter | Compiler |
|---|---|---|
| Start time | Fast | Slow |
| Execution speed | Slow | Fast |
| Optimization | None | Extensive |
| Memory | Less | More |
Summary
Section titled “Summary”- Interpretation: fast start, slow execution (Ignition)
- Compilation: slow start, fast execution (TurboFan)
- JIT combines both — starts interpreting, compiles hot paths
- Can deoptimize when assumptions break