Java: Why is it still slow?
I keep running across pieces like this DeveloperWorks article called Java theory and practice: Urban performance legends revisited, discussing the performance benefits of Java – that it is in fact faster than C or C++.
The article makes some convincing arguments. In fact most of the arguments I hear are convincing. However, performance of real-world java apps still leaves a lot to be desired, and certainly is leagues behind C/C++ apps.
I’ll give you an example. I’ve personally been involved in two projects that essentially involve creating a Web proxy that does various fancy things. One version in Java, the other in C. The Java version tops out at maybe 200 simultaneous requests per second, while the C version is somewhere above 1000/sec. The Java version is actually a second generation, optimized rewrite of an earlier Java version that brought about significant performance improvements. Still, it lags far behind the C version.
You can try this yourself. Grab Axis and gSOAP. Write a simple service in each. Now throw load at them. Lots of load. You’ll see the same thing: gSOAP will be many times faster than Axis and handle much more simultaneous load.
Perhaps Java is very fast but people tend to write slow, inefficient programs with it? I have a theory that the fact that it’s easier to write code in Java than C leads people to write more code than they would in C to do the same function, which ends up causing bloat and slowness.
I don’t have a religious axe to grind here – I’d be very happy if Java was in fact very fast. However, pretty much everything I see in practice points to Java being much slower than C/C++. What’s your experience?
Manage your expenses via Email, SMS, iPhone, Twitter, Voice (Call and say your expense), IM (Yahoo, AIM, MSN), or Web.
Comments(3)
A lot of it, I think, is memory and thread bound. I am not certain Java can match a C application as far as memory usage and threading go.
Well, the article above argues precisely that Java’s memory handling is in fact better than C/C++. Memory usage, as in an equivalent item taking more memory with Java than with C, is another story.
Java might be “platform” indepedent but results are very dependent on the platform.