Performance optimization in software development is an ongoing challenge, and one of the most powerful tools that makes Java performant is its Just-In-Time (JIT) compilation. Unlike traditional compilation techniques, JIT compiles code at runtime, improving execution speed dynamically. But how significant is the impact of JIT compilation on a Java programs performance?
This study was for the course EDAA35 Software system evaluation at LTH and was done together with Sara Reimers. Our work was based on using R to study the execution time differences when JIT compilation is enabled versus when it is disabled, using different sorting algorithms as test cases.
Java and JIT under the hood
Java’s portability is largely attributed to its compilation model. Unlike languages that compile directly into machine code, Java compiles source code into an intermediate form called bytecode. The Java Virtual Machine (JVM) then interprets this bytecode and executes it. However, interpretation can be slow, which is where JIT compilation comes in.
JIT compilation optimizes performance by compiling frequently executed bytecode segments into native machine code on the fly. This means that as a program runs, it becomes progressively faster as the JVM learns which parts of the code are executed often and optimizes them accordingly.
Measuring the impact
To quantify JIT’s effect on execution time, we performed experiments using three different sorting algorithms: Merge Sort, Insertion Sort, and Bubble Sort. Each algorithm was executed with and without JIT compilation enabled, and the execution times were measured over multiple iterations and datasets.


Comparing the graph of execution times when running Merge sort with JIT enabled (see Figure 1) and disabled (see Figure 2) a noticeable difference can be seen. When JIT is enabled, the execution times steadily decrease until reaching a phase where the differences are small, compared to when JIT is disabled and a trend can’t be found.
Key findings
- JIT Compilation Significantly Reduces Execution Time: Across all sorting algorithms, enabling JIT reduced execution time, sometimes by a factor of 10 or more.
- Performance Gains Increase Over Time: The JVM dynamically optimizes execution as it detects repetitive code patterns, explaining the initial performance dip followed by stabilization.
- Algorithm Choice Still Matters: While JIT improves performance, inherently inefficient algorithms (e.g., Bubble Sort) remain significantly slower than optimized ones like Merge Sort.
Conclusion
JIT compilation is a crucial optimization strategy in Java, dynamically reducing execution time as programs run. Our experiments confirmed that enabling JIT can lead to substantial speed improvements. However, algorithm choice remains a dominant factor in overall efficiency. To maximize performance, developers should not only rely on JIT but also carefully select appropriate algorithms.
Next steps in our studies
To build on this study and further evaluate the behaviour and effects of JIT, the following fields will need to be studied:
- Exploring JIT Optimization Levels: Different JVM implementations provide varying JIT strategies that could further enhance performance.
- Parallel Processing with JIT: Investigating how JIT interacts with multi-threaded applications.