O'Reilly logo

Web Performance Tuning by Patrick Killelea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Performance Tips: What You Can Do

OK, so Java performance will improve in future generations of compilers and JVMs, but you need better performance now. What can you do? There are dozens of techniques for improving Java performance. Let’s go through the major ones, starting at the source code level.

Get the Best VM for Your Runtime Platform

If you know your code will be running on a particular platform, say because it is server-side code, be sure you have the latest VM for that platform. You probably also want a VM written by the operating system vendor because the vendor presumably knows the most about optimizing Java for that OS. So use the MRJ on the Mac, Digital’s VM on Digital Unix, and so on. Microsoft also makes the fastest VMs for Windows, but be careful when using Microsoft Java products lest you end up writing code that won’t run anywhere except on Windows.

Along with using the best VM for your platform, you should take advantage of all available performance boosters, such as native thread packages and JITs.

Profile Your Code

First, look at your Java code as you would look at C/C++ code, and do all of the optimizations you would do there. Look in Chapter 15, under the section on optimizing C, for the standard ideas.

To do code profiling in Java, you compile with the -prof option, like this:

javac -prof MyClass.java

This does profiling based on actual execution times, but doesn’t count the number of times any set of bytecode is used. The result is a profile file. You can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required