Why Java Will Always Be Slower than C++
jelovic.com
jelovic.com
It is fairly well-known. I wasn't too surprised when I saw it show up on Reddit recently, but I was disappointed to see it show up here. It's getting harder each day to see any kind of difference between Reddit and Hacker News.
This becomes even more important as parallel and computing becomes more important. Designing and implementing systems that run on a single CPU isn't all that hard given all the tools, libraries and abundance of literature developers have access to at little or no cost. Writing software that spans CPUs and even computers is a different matter.
Writing an application like Twitter isn't hard. Making it scale shouldn't be, but apparently still is. Doing twitter in C++ might offset the problems they experience somewhat, but not meaningfully so.
A lot of people forget that. Most of the software I've encountered that displayed performance problems did so because of endemic architectural flaws and bad code. Pointless complexity usually leads to slow software.
In most well-written applications, you wouldn't be able to tell the difference between a version on C++ or a version in Java, because the software is rarely the bottleneck. Obvious exceptions are applications like games and 3D animation systems, where there's a lot of computation going on all the time.
A well-written word processor in Ruby might well feel MORE responsive than a poorly written one in C++, for example.
And it will always be the case that the clever algorithm or data structure is much better at getting some cycles back than switching language.
Part of the article is also wrong. A dynamic lookup can often be avoided if you have a dataflow analysis phase in the compiler for instance. It is almost "the" optimization for OO languages like Java.
Just like C++ is slower than assembly, which is slower than using microcode, which is slower than coding at the logic-gate level.
It's not that writing Java code is easier than writing C++. The fact is that writing memory leaks is a lot harder in Java than it is in C++.
Ummm, yeah, C++ can magically access the disk faster than Java. NOT!!
Yes, in C++.
As a side thought: if Apple were dumb enough to embrace Java instead of sticking to Objective-C, I doubt that OSX-powered iPhone (with a full-sized WebKit) would have been possible. Just look at Microsoft and their Vista disaster, this what happens when you start believing into "megahertz and gigabytes are cheap".
My point being, he cited a lot of example that would have been no slower in Java.
this what happens when you start believing into "megahertz and gigabytes are cheap".
As I say to the people I work with all the time, yes computational power is cheap, but it's cheap for everyone, our competitors included. The ability to throw raw power at a problem is not a competitive advantage.
As an aside, I wish CS was taught like that. "You are never going to need to write your own sort ever, but we are going to teach you about sorting so you understand that smart algorithms always beat brute force. Pay attention."
My personal opinion of Java is that its shortcomings were either necessary for or worth putting up with for a world of applications on demand running on heterogenous client devices (i.e. the original applet vision). Now that it's mainly used in known environments (i.e. your own servers) it has to compete on its merits alone, and that's where it struggles. But I really don't mind if other people want to shackle themselves to it :-)
The same may not apply for other projects. I for one spend most of my time worrying about IO, availability and how to best take advantage of multiple CPUs and cores. In this, C++ isn't exactly giving developers anything for free (concurrency still not even being part of the language).
As for Java on mobile: there are projects that are going that route. I'd wait and see before I postulated whether this is a good idea or not.
I don't really understand how Vista fits into this discussion at all. In my opinion, Vista is the result of developers being paralyzed by the sheer weight of their legacy code and interoperability with legacy code. Completely different issue.
I'm sure you've seen "Java: Please Wait..." on tiny mobile screens with famous Java logo (cup of coffee). I am yet to run into "Please Wait: Objective-C..." screen on the iPhone.
I think the moral of the story is: to get the maximum performance out of your memory management system, you need to know how it works. This applies equally well to C++.