Write Better Algorithms
There are a lot of details about Java that affect the performance of an application, and a lot of
tuning flags are discussed. But there is no magical -XX:+RunReallyFast option.
Ultimately, the performance of an application is based on how well it is written. If the pro-
gram loops through all elements in an array, the JVM will optimize the array bounds-check-
ing so that the loop runs faster, and it may unroll the loop operations to provide an additional
speedup. But if the purpose of the loop is to find a specific item, no optimization in the world
is going to make the array-based code as fast as a different version that uses a HashMap .
A good algorithm is the most important thing when it comes to fast performance.
Write Less Code
Some of us write programs for money, some for fun, some to give back to a community, but
all of us write programs (or work on teams that write programs). It is hard to feel like a con-
tribution to the project is being made by pruning code, and there are still those managers who
evaluate developers by the amount of code they write.
I get that, but the conflict here is that a small well-written program will run faster than a large
well-written program. This is true in general of all computer programs, and it applies spe-
cifically to Java programs. The more code that has to be compiled, the longer it will take un-
til that code runs quickly. The more objects that have to be allocated and discarded, the more
work the garbage collector has to do. The more objects that are allocated and retained, the
longer a GC cycle will take. The more classes that have to be loaded from disk into the JVM,
the longer it will take for a program to start. The more code that is executed, the less likely
that it will fit in the hardware caches on the machine. And the more code that has to be ex-
ecuted, the longer it will take.