Making the JVM Fast

Java was a very slow performer when it first came out. Then it started becoming a contender for other compiled languages like C and C++. In fact, Java is faster than C++ in some cases. But in general it is a little slower.

All code is interpreted by the Java Virtual Machine. However for methods that are used very frequently, the JVM compiles the code and then you get really good performance. The trick is that the JVM can see how the code is used many times. Then it has the knowledge needed to optimize the compilation.

With the default options, code written in smaller sized methods runs faster. The reason for this is the the JVM will not compile methods that are too large. You can modify this behavior with some options. In fact you can even force the JVM to compile everything. While this might seem to be best, it is not. You should let the JVM interpret the code first. Only after interpreting a method many times can it make the best optimizations for compilation.