CSArchitecture & RuntimeDiagramAdvanced
JIT Compilation
KO: JIT 컴파일 (Just-In-Time)·EN: JIT Compilation·JA: JITコンパイル·Just-In-Time Compilation
Dynamically compiling hot bytecode paths into optimized native machine code at runtime using live profiling data
Table of Contents
Structure Diagram
JIT Tiered Compilation, Profiling & Deoptimization Cycle
2/42. Detect Hot Loop— Frequent calls spotted
Frequent calls spottedQuick Answer
What is JIT Compilation?
Dynamically compiling hot bytecode paths into optimized native machine code at runtime using live profiling data. It is a core concept in Architecture & Runtime within CS.
Core Principles
JIT (Just-In-Time) Compilation blends fast interpreter startup with native-code speed by compiling hot code paths while the program is running.
- Tiered Compilation: Execution starts in a fast bytecode interpreter that gathers live type and branch profiles. Frequently executed functions are promoted to optimizing compilers (e.g., V8 TurboFan, JVM C2) for aggressive inlining and native codegen.
- Speculative Optimization & Deopt: JIT assumes observed types stay stable; if a new type appears, it safely deoptimizes back to bytecode.
Practical Takeaways
- Account for warm-up time: Newly booted JVM/Node.js instances run slower until JIT tiers stabilize—always warm up before benchmarking or shifting full production traffic.
- Keep hot paths monomorphic: Passing consistent object shapes/types lets V8 inline caches stay fast and avoids repeated deoptimizations.
- Consider AOT for short-lived serverless: When processes live seconds (e.g., Lambda), GraalVM Native Image or Go/Rust avoids JIT warm-up cost.
Notable Examples
- V8 Engine: Ignition → Sparkplug → Maglev → TurboFan pipeline.
- HotSpot JVM: Interpreter → C1 → C2 tiered compilation.
- LuaJIT & PyPy: Tracing JITs bringing dynamic languages near C speed.