LearnViz CompSci
Home / Learn / Languages & Compilers / Just-In-Time Compilation

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

  1. The program starts by interpreting bytecode.
  2. A profiler counts which code is hot.
  3. A hot function is compiled to native machine code.
  4. Later calls use the fast version.
  5. 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

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. 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?
Compiling hot code at runtime. It belongs to Languages & Compilers and is an advanced-level topic.
Where do people use Just-In-Time Compilation?
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.
What is the most common mistake with Just-In-Time Compilation?
Warm-up time delays peak performance, so short programs may not benefit.
What should I learn before this topic?
Start with Data-Flow Analysis, the topic just before it in Languages & Compilers.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Languages & Compilers quiz.
Is Just-In-Time Compilation hard to learn?
It is an Advanced topic. Expect to read the explanation more than once and to connect it with earlier topics. Working through a small example by hand helps most.
How long does it take to learn Just-In-Time Compilation?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Just-In-Time Compilation?
Data-Flow Analysis, LLVM, Inlining are closely connected. The full list is in the related topics section of this page.
What should I study after Just-In-Time Compilation?
Continue with LLVM, the next topic in Languages & Compilers.

Related topics