Just-In-Time (JIT) compilation is a runtime optimization technique that converts interpreted bytecode or intermediate representations into native machine code while a program is running, rather than ahead of time. By compiling code at the moment it's needed, JIT compilers combine the portability of interpreted languages with performance close to that of statically compiled languages, giving long-running applications a real speed boost.
JIT compilers use several strategies to squeeze out performance. Hotspot detection identifies frequently executed code paths and prioritizes them for compilation. Speculative optimization generates fast native code based on observed runtime behavior, with fallback mechanisms (deoptimization) if those assumptions turn out to be wrong. Tiered compilation, used by the Java HotSpot JVM, starts with quick but less optimized compilation and progressively applies more aggressive optimizations to the hottest methods.
JIT compilation powers many widely used runtime environments. The Java Virtual Machine (JVM), .NET's Common Language Runtime (CLR), the V8 JavaScript engine (used in Chrome and Node.js), and LuaJIT all rely on JIT techniques for high performance. Knowing how JIT works can help developers write faster code. For example, keeping functions monomorphic in JavaScript helps V8's JIT generate specialized machine code. The tradeoff is higher memory usage and warmup time as the JIT analyzes and compiles code paths during early execution.