Hotspot performance

A few days ago Kohsuke Kawaguchi posted a really cool blog entry titled a “Deep dive into assembly code from Java”. It's a pile of fascinating (if gory) assembly code with commentary. Some things to notice:
  • Really aggressive inlining
  • Even storage allocation & initialization gets inlined - new T() really is as efficient as C's alloca() (and it beats the pants off malloc())
  • Careful management of cache prefetching
  • Deep understanding of variablity between the flavors of x86 machines
  • Loop unrolling with warmup/cooldown
  • "theorum proving away" of array index checks (and many other things)
  • much cleverness with locks
I've had several run-ins in recent months with crusty C (and a few Fortran) programmers who say "you must be faking your benchmarks!". Nope. The HotSpot crew has done a truly great piece of work.

But, but, but, Java Is Slow!
Everyone knows that in the C++ world, after all they've been saying it for over a decade so it MUST be true!

Posted by J.T. Wenting on April 06, 2008 at 11:46 PM PDT #

These are the twits that just repeat the politically correct litany, without actually running benchmarks. Java screams! Java's startup time is a little slower than a C program (at least, for the first app), but after that... Wicked... C's startup speed is really a fraud: mostly it's because libc is already paged in.

Posted by Speed Freak on April 07, 2008 at 02:37 AM PDT #

Hi All,

I have had many discussions over the last 2 years regarding what I have done with java. Back in 2003 or so I started with web services (Axis) and 1.4.x of java and went from over 60 seconds to around 4-5 mseconds today (internet 20msec local to around 60-70msec 1500-2000 miles away from the server using cheap PC for a server. Yes, java can be fast if you Architect/Design/implement correctly and keep up with the latest versions. Just going from 1.6.0_01 to 1.6.0_02 showed big gains.
Yes java can do well but it needs help from you do achieve those gains.

Tony Anecito
Portal for kids.

Posted by Tony Anecito on April 07, 2008 at 07:23 AM PDT #

Hi All,

I forgot to mention the 4-5msec was measured at the RIA after the SOAP message was decoded. I am using JAXWS and not Axis anymore. I was also able to get my servlet cache down to below a nanosecond and below 5 microseconds after adding more logic for multi-tier cacheing where the Java client also had a cache. I am using a AMD64 X2 +5200 on windows 2000 professional with 1GBps ethernet and a DLink gaming router. I feel sure if I used an extreem edge P4 or a Xeon processor with maybe linux the time measured at Apache logs on the server side of the SOA I engineered would be below a millisecond for say 2 packets measured on my RIA on my intranet.

Yes Java rocks if you help it with something built from the ground up for performance.


Posted by Tony Anecito on April 07, 2008 at 01:28 PM PDT #

Yesterday I was making some tests with DES coded in two versions, in Java and C. Both codes were very well optimized. Then I did some benchmarks, with C I got 53,000,000 keys/min, and with Java I got 60,000,000 keys/min!

Note that I was using the JRE 1.6.0_05 and gcc-3.4.5 (MingW), both on Windows Vista.

Java is not slow any more! In old days it was very slow, but with JRE 1.6 Sun did a very good job.

What some people forget is that with JRE 1.6 we have JIT as default. In other words the most used Java methods are compiled to "machine code", so our bytecode after JIT will run fast as C.

Posted by Graciliano Monteiro Passos on April 07, 2008 at 03:32 PM PDT #

The fun part is that I believe we are only at the beginning of the realm of possible dynamically derived optimizations that could be applied. It is my understanding that to date, cross frame optimizations have been ignored. So there is every indication that this gap is only going to get bigger unless someone figures out how to embed the equivalent to HotSpot/JIT in competing runtimes.

Now to tackle he next problem, GC induced latency. It is the \*only\* problem keeping Java out of a number of domains.

Posted by Kirk on April 07, 2008 at 04:18 PM PDT #

Java's performance is definitely not bad. In fact sometimes it's faster than reasonable C code. But there are still some (rare?) cases where hotspot doesn't get it right - even for simple numeric benchmarks.
Just take a look at
or my modified version of the fannkuch benchmark which gives the hotspot server VM a chance of warming up (results under

Posted by Stefan Krause on April 07, 2008 at 04:26 PM PDT #

This doesn't surprise me and I'm pretty happy to see this constant improvement as ten years ago I was getting laughs when I was betting about the fact tha t Java performance would have been better than C/C++ at least in some areas.

BTW, I have a mental note about writing a native accelerator for an image demosaicing algorithm - the latest benchmarks in that area go back to 2004, I should run them again and perhaps I'll be able to remove that note.

Posted by Fabrizio Giudici on April 07, 2008 at 08:29 PM PDT #

Post a Comment:
Comments are closed for this entry.



« July 2016