Advanced Topic 38 of 50 Languages & Compilers
Just-In-Time Compilation
Compiling hot code at runtime.
How it works
A just-in-time compiler translates code into machine code at run time, often starting with an interpreter or baseline compiler and compiling frequently executed hot methods or loops with optimizations guided by run-time profiling. It can specialize code based on observed types and speculate, with deoptimization fallbacks if assumptions fail. Tiered compilation balances startup speed and peak performance. Engines such as HotSpot, V8, LuaJIT and the .NET RyuJIT use it.
Step-by-step walkthrough
- The program starts by interpreting bytecode.
- A profiler counts which code is hot.
- A hot function is compiled to native machine code.
- Later calls use the fast version.
- It can optimize using real runtime data, and deoptimize if assumptions break.
Where it is used
Managed languages and dynamic languages such as Java, JavaScript, C# and Lua reach near native speed using JIT compilation, and database engines JIT query expressions.
Common pitfall
Warm-up time delays peak performance, so short programs may not benefit. JIT compilation uses memory and CPU in the background, and writable executable memory raises security concerns that some platforms such as iOS restrict. Performance can be unpredictable when deoptimizations occur. Benchmark with warm-up, avoid patterns that break optimization such as changing object shapes, and profile.
Where it fits in the course
Just-In-Time Compilation is topic 38 of 50 in Languages & Compilers, rated Advanced. It follows Data-Flow Analysis. The next topic is LLVM.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Languages & Compilers quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Languages & Compilers quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Just-In-Time Compilation?
Where do people use Just-In-Time Compilation?
What is the most common mistake with Just-In-Time Compilation?
What should I learn before this topic?
How can I practice it?
Is Just-In-Time Compilation hard to learn?
How long does it take to learn Just-In-Time Compilation?
Which topics are related to Just-In-Time Compilation?
What should I study after Just-In-Time Compilation?
Related topics
- Data-Flow Analysis (Languages & Compilers)
- LLVM (Languages & Compilers)
- Inlining (Languages & Compilers)
- Type Systems (Languages & Compilers)
- Time Complexity (Algorithms)
- Real-Time Operating Systems (Operating Systems)
- Real-Time Constraints and Scheduling (Mobile, Embedded & IoT)