Just-in-time compilation (JIT) is a technique where code is only turned into machine code while a program is running. It doesn't happen in advance, but at the moment that code is actually needed. The component that does this is called a JIT compiler.
A processor only understands machine code. Whatever a developer writes has to be translated at some point, and there are three ways to do it. Comparing them to translators makes the difference easy to see.
Imagine you want an English book read aloud to a French-speaking audience. You have three options:
A traditional compiler is a translator who translates the whole book beforehand. The reading goes quickly, but you have to wait until the translation is finished.
An interpreter translates each sentence on the spot. You can start straight away, but if the same sentence comes up again, they translate it all over again.
A JIT compiler is an interpreter who notes which sentences keep coming up. They write those out once, so they can read them straight off the page from then on.
That last option is exactly what JIT does. The program starts quickly, just as it would with an interpreter. Code that runs often soon becomes as fast as compiled code. Sometimes it's even faster, because the JIT compiler can see how the program is actually being used.
The name is borrowed from just in time manufacturing, the Toyota method of only making what's needed, when it's needed. The term was popularised by Java, with James Gosling using it from 1993. The idea fits neatly. You only compile when it's needed, and only what's needed.
The technique itself is older than the name. Software systems have been using JIT techniques since the 1960s. Early examples include LISP and tools for regular expressions. Later, the Smalltalk and Self languages took the idea further. What was learnt there found its way into Java's HotSpot JVM, which brought JIT compilation to a mass audience.
There are three ways to translate code into machine code. Each has its own strengths and weaknesses.
With ahead-of-time compilation (AOT), a compiler turns all the code into machine code before the program runs. You end up with a file the processor can execute directly. Languages such as C, C++, Rust and Go work this way.
The upside is that the program starts quickly and runs at full speed from the outset. The downside is that the machine code is built for one type of processor and operating system. To run the program anywhere else, you have to compile it again.
An interpreter reads the code and runs it line by line. There's no separate compile step, so you can get going straight away. The same code runs anywhere the interpreter runs.
The trade-off is speed. An interpreter translates the same code over and over, even if it runs a thousand times in a row. That adds up.
JIT combines the two. Source code is often converted in advance into bytecode, an intermediate form that isn't tied to any one processor. While the program runs, an interpreter executes that bytecode. Code that runs often is handed to the JIT compiler and turned into machine code after all.
That way, you keep the flexibility of an interpreter. At the same time, you get the speed of compiled code for the parts that really matter.
This table puts the three side by side:
AOT compilation | Interpretation | JIT compilation | |
When it's translated | In advance, all at once | While running, over and over | While running, once per piece of code |
Speed right after start-up | High | Low | Low, then rises |
Speed after a while | High | Low | High |
Runs on any platform | No, needs recompiling | Yes | Yes |
Memory use | Low | Low | Higher |
Examples | C, C++, Rust, Go | Shell scripts, standard Python | Java, C#, JavaScript |
Every JIT compiler works slightly differently, but the basic process is the same.

With languages such as Java and C#, the process starts before the program even runs. A standard compiler turns the source code into bytecode. In Java this is called Java bytecode. In .NET it's called Intermediate Language (IL). That bytecode runs on any machine with the right runtime, such as the Java Virtual Machine (JVM) or the .NET runtime.
JavaScript skips this step. The browser receives the source code itself and builds its own bytecode internally.
When the program starts, an interpreter runs the bytecode. Meanwhile, the runtime keeps track of which pieces of code run most often. This is called profiling. A function called thousands of times or a loop that keeps going round counts as hot code.
Only hot code is worth compiling. Code that runs just once is better left to the interpreter, because compiling takes time too.
Once code is hot, the JIT compiler turns it into machine code for the processor the program is running on at that moment. At the same time, it optimises the code.
This is where JIT really shines. An AOT compiler has to guess how the program will be used. A JIT compiler can see it. It knows which paths through the code are actually taken, which data types are passing through and which processor is in the machine. It tailors the machine code to match.
Sometimes an assumption stops holding true, for example when a different data type suddenly turns up. The runtime then throws away the optimised code. The code goes back to being interpreted and is recompiled later. This is known as deoptimisation.
The machine code produced by the JIT compiler is stored in the code cache. When the same function is called again, the runtime picks up the cached version straight away. Nothing needs translating.
Optimising takes time. The better the optimisation, the longer compilation takes. That's why many runtimes work with several levels, an approach known as tiered compilation.
The JVM is a well-known example. It has a client compiler (C1) and a server compiler (C2). C1 compiles quickly with simple optimisations, so code speeds up early on. If a piece of code keeps running heavily after that, C2 takes over. C2 takes longer but produces much faster machine code. JavaScript engines in browsers use a similar multi-tier set-up.
Chances are you've already used code today that ran through a JIT compiler. These are the most common places:
Java and other JVM languages: Kotlin, Scala and Clojure all run on the JVM, which uses JIT compilation.
.NET: C# and F# are compiled to IL, which the .NET runtime turns into machine code while the program runs.
JavaScript: every modern browser has an engine with a JIT compiler, such as V8 in Chrome and SpiderMonkey in Firefox. Node.js runs on V8 as well.
PHP: PHP has had a built-in JIT compiler since version 8.
Python: the standard version mainly relies on an interpreter. Alternatives such as PyPy use JIT.
Data science and AI: libraries such as Numba and JAX compile Python functions just in time, so heavy calculations run much faster.
There's a reason JIT compilation is so widely used. These are the main benefits:
High performance: hot code runs as machine code, often close to the speed of AOT-compiled code.
Optimised for real-world use: the compiler sees which code and data actually pass through.
Tailored to the machine: the machine code is built for the exact processor the program runs on.
One version for every platform: you ship bytecode and the runtime handles the rest.
Well suited to dynamic languages: in languages such as JavaScript, data types are only known at runtime. JIT is what makes those languages fast.
Those benefits come with a few clear drawbacks:
Warm-up time: a program doesn't run at full speed straight away. The runtime first has to work out what's hot and compile it. For short tasks, the JIT compiler may never get a look-in.
More memory and CPU: the compiler, the profiling data and the code cache all take up memory. Compiling also uses processing power the program itself can't use.
Less predictable: how fast code runs depends on what the compiler decides at that moment. That makes performance harder to measure and predict.
Security risks: a JIT compiler writes code into memory and then executes it. Systems normally keep those two things strictly separate to make attacks harder, and JIT has to be an exception. That's why bugs in JIT compilers are a popular target for attackers, especially in browsers.
Not allowed everywhere: for the same reason, some platforms, such as iOS, don't allow JIT compilation in regular apps. There, code has to be compiled in advance.
The right approach mainly depends on how long your program runs.
If start-up time matters most, AOT is usually the better fit. Think of these use cases:
Serverless functions: these often run briefly and have to warm up again on every cold start.
Mobile apps: a fast start and low battery use matter here.
Command-line tools: these are often done in under a second.
Embedded systems: memory is in short supply.
If your program runs for a long time, JIT is often the better choice. Think of web servers, APIs and back-end systems that run for days or weeks at a stretch. By the time everything is running at full speed, the warm-up is long forgotten. On top of that, the JIT compiler keeps optimising based on how the system is actually used.
You don't always have to pick one or the other. Java and .NET both offer ways to compile code to machine code in advance, for example to speed up start-up in the cloud. Some runtimes can also save data from a previous run to shorten the warm-up. So focus on what your application needs, not just on what a language does by default.
JIT compilation only turns code into machine code once the program is running. That makes for a smart division of labour. Code that runs once is interpreted. Code that keeps coming back is compiled and optimised based on how the program is really used.
The result is fast code that runs anywhere. The price is a longer warm-up, higher memory use and extra attention to security. If your software runs for a long time, JIT is often the best choice. If every millisecond at start-up counts, AOT is the better fit.
The name says it all, really. Just like just in time on the factory floor, it's about doing the right work at the right moment.
Both. Java code is compiled in advance into bytecode. While the program runs, the JVM first executes that bytecode with an interpreter. Code that runs often is then turned into machine code by the JIT compiler.
Yes. Modern JavaScript engines use JIT compilation, such as V8 in Chrome and Node.js and SpiderMonkey in Firefox. Without JIT, demanding web applications would be far slower.
AOT compiles all the code before the program runs. JIT compiles while the program runs, and only the code that's used often. AOT starts up faster. JIT can optimise better based on real-world use.
At start-up, all the code still runs through the interpreter. The runtime first has to find out which code is hot and compile it. Only then does the program run at full speed. This is known as the warm-up.
No. An interpreter translates code every time it runs. A JIT compiler turns code into machine code once and reuses it after that. In practice, the two often work together: the interpreter gets things going and the JIT compiler takes over the work that keeps coming back.
The name is borrowed from it. As with Toyota's method, it's about only making what's needed, when it's needed. In the factory, that means parts. In JIT compilation, it means machine code.