I have a program I ported from C to Java. Both apps use quicksort to order some partitioned data (genomic coordinates).
The Java version runs fast, but I\'d like to get
Also try tweaking the runtime arguments of the VM - the latest release of the VM for example includes the following flag which can improve performance in certain scenarios.
-XX:+DoEscapeAnalysis
Here's what I would do, in any language. If samples show that your sort-comparison routine is active a large percentage of the time, you might find a way to simplify it. But maybe the time is going elsewhere. Diagnose first, to see what's broken, before you fix anything. Chances are, if you fix the biggest thing, then something else will be the biggest thing, and so on, until you've really gotten a pretty good speedup.
Don't optimize prematurely.
Measure performance, then optimize.
Use final variables whenever possible. It will not only allow JVM to optimize more, but also make your code easier to read and maintain.
If you make your objects immutable, you don't have to clone them.
Optimize by changing the algorithm first, then by changing the implementation.
Sometimes you need to resort to old-style techniques, like loop unrolling or caching precalculated values. Remember about them, even if they don't look nice, they can be useful.
Profile and tune your java program and host machine. Most code follows 80/20 rule. That is 20% of code 80% of time, so find that 20% and make it as fast as possible. For example, the article Tuning Java Servers (http://www.infoq.com/articles/Tuning-Java-Servers) provides a description of drill down from command line and then isolate the problem using tools like Java Flight recorder, Eclipse Memory Analyser, and JProfiler.
If your algorithm is CPU-heavy, you may want to consider taking advantage of parallelisation. You may be able to sort in multiple threads and merge the results back later.
This is however not a decision to be taken lightly, as writing concurrent code is hard.
Use a profiler:
Use the latest version of JVM from your provider. Incidentally Sun's Java 6 update 14 does bring performance improvements.
Measure your GC throughput and pick the best garbage collector for your workload.