views:

730

answers:

4

Is there any performance to be gained these days from compiling java to native code, or do modern hotspot compilers end up doing this over time anyway?

+1  A: 

Memory performance or CPU performance? Or are they the same these days?

My only evidence is anecdotal and on a different platform: after porting a bunch of CPU-hungry apps to C# (.NET 2.0), I did not notice substantial loss in performance (I do not consider 10% substantial). Well written code seems to perform well on a variety of architectures.

Most apps spend/waste time with:

  • IO operations that will not benefit from static (compile-time) analysis.
  • Bad Algorithms that will not benefit from static analysis.
  • Bad Memory layouts in critical CPU inner loops. While it is technically possible that compilers help us here, I have yet to see a real compiler do anything interesting.

So based upon my experience, unless you are writing a video codec, there is no benefit to compiling Java apps vs. just relying upon the hotspot compilers.

Frank Krueger
+3  A: 

There was a similar discussion here recently, for the question What are advantages of bytecode over native code?. You can find interesting answers in that thread.

Einar
+1  A: 

Some more anecdotal evidence. I've worked on a few performance critical real-time trading financial applications. I agree with Frank, nearly every time your problem is not the lack of being compiled, it is your algorithm or data structure. Modern hot-spot compilers are very good with the right code, for example the CERN Colt library is within 90% of compiled, optimised Fortran for numerical work.

If you are worried about speed I'd really recommend a good profiler and get evidence as to where your bottlenecks are - I use YourKit and have been very pleased.

We have only resorted to native compiled code for speed in one instance in the last few years, and that was so we could use CUDA and get some serious GPU performance.

Nick Fortescue
A: 

Your question is a little large, the answer vary a lot

  • If you are using Just In Time compilation (JIT) or not
  • When you are using,, if your process is executed for a long time or not

All recent JVM use JIT, but on old JVM the java code is several time slower that native code.

If you have a server that run for a long period of time or batch that execute the same code again and again, the difference and up being very low.

We wrote the same batch both in C++ and in Java and run it with different dataset, the result differ for about 3 second, with dataset taking from 5 minutes to several hours.

But be careful, they are special case that there will be an important difference, for example the batch that need a lot memory.