Skip to main content

JIT Compilation

Just-in-Time Compilation

In Turkish
JIT derleme
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/jit-compilation

In short

JIT compilation turns the busiest parts of a program into machine code while it runs, combining an interpreter's quick start with compiled speed.

What is JIT compilation?

A just-in-time (JIT) compiler works inside a running program. The program starts in an interpreter, which can run code right away, while the runtime counts how often each function and loop runs. Code that turns out to be hot, meaning it runs many times, is compiled into native machine code for the processor, and later calls run that faster version instead.

Because it compiles while the program runs, a JIT compiler can optimize for what actually happens: if a function is only ever called with numbers, it can produce code made for numbers. If that guess later proves wrong, the runtime throws the optimized code away and falls back to slower code, which is called deoptimization. V8 in Chrome and Node.js, the Java HotSpot virtual machine and .NET all work this way, usually with several tiers, from quick to highly optimized.

JIT compilation sits between the two classic approaches. Ahead-of-time (AOT) compilation, as in C, Go and Rust, translates everything before the program runs; a plain interpreter translates nothing. JIT pays in warm-up time, since code is slow until it gets compiled, and in memory, which is why short-lived programs, and platforms that forbid generating code at runtime such as iOS apps, use AOT instead. Python added an experimental JIT compiler in version 3.13.

Key takeaways

  • A JIT compiler turns frequently run code into machine code while the program runs.
  • Programs start in an interpreter, and hot code is compiled once it proves worth it.
  • What it sees at runtime lets a JIT specialize code, and deoptimize when a guess fails.
  • The cost is warm-up time and memory; ahead-of-time compilation avoids both.

Example

Watching V8 compile a hot function in Node.jsjavascript
// Run with: node --trace-opt hot.js
function add(a, b) {
  return a + b;
}

let sum = 0;
for (let i = 0; i < 1e6; i++) {
  sum = add(sum, i); // a million calls make add "hot"
}
console.log(sum); // 499999500000

// Among V8's log lines, add is compiled by Maglev, then by TurboFan:
// [marking … <JSFunction add …> for optimization to MAGLEV, …, reason: hot and stable]
// [marking … <JSFunction add …> for optimization to TURBOFAN_JS, …, reason: hot and stable]

Readers ask

Is JIT compilation faster than ahead-of-time compilation?

Not in general. Ahead-of-time compiled programs start fast and need no compiler while they run. A JIT starts slower but can use what it sees at runtime, so long-running programs such as servers can match, and sometimes beat, ahead-of-time code. Which wins depends on the workload.

Does Python have a JIT compiler?

The standard CPython added an experimental JIT compiler in version 3.13, switched off by default. PyPy, an alternative Python implementation, has used a JIT for years and often runs pure Python code several times faster.

See also

Sources

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings