by codewright · 14y ago · 0 comments
I really want real numbers, not idle conjecture. Gosling was fond of speculating that Java would eventually be faster than C and C++ because of $COOL_FEATURE_X, but nothing ever materialized or made enough of a difference.
Concurrent GC didn't make up the difference. JIT didn't make up the difference. Why would I believe anybody else bringing the same message?
This cyclical "we're gunna be faster and here is the cool compiler research saying so!" is why the programming language community has thoroughly alienated my colleagues that work in systems.
They can't afford to build their systems on speculation, it HAS to work. They believe nothing anybody says about programming languages now.
What's the most impactful territory to conquer that could help make up the difference?
Rust's design allows for a subset of valid programs that could be constructed in C++. It's the same kind of thinking that Haskell utilizes. The type system is useful in Haskell because it disallows potentially invalid programs giving you a smaller space to reason about. (cf. Total programming)
However, that subsetting means avenues and opportunities for optimization are eliminated. Optimization sometimes means doing something batshit.
A high-level 6502 emulator a friend wrote in x86 asm comes to mind.
Certainly, if you need something to be shipped soon, and you need it to be performance-competitive with C++, don't use Rust. Despite the fact that it's backed with LLVM, the compiler is quite immature.
I don't think at this point that any significant avenues for optimization are closed off in the Rust language design relative to C++. The safety checks are all designed to be optional.
Uhm, I'd say Java already is faster than C++ for all intents and purposes. If your codebase is >50KLOC and the number of developers on your team is more than, say, 4 or 5, then some crazy optimizations that are possible in C++ for small applications are out of the question, and the JIT plus the GC more than make up the remaining difference. Also, modern performance-critical software requires good concurrency, and Java has stuff like fork-join, that I'm not sure is available in standard C++ (it is, of course, available in Cilk).
So, even though it's hard to provide hard evidence (because most benchmarks are <50KLOC and written by one or two developers at most), I'd say from experience that Java already is faster than C++ in practically all circumstances (except, maybe, scientific-computation applications), not counting startup time. The only missing piece in the Java performance puzzle is value types and arrays-of-structs, and those, I believe are coming, and should make scientific-computation faster in Java as well.
50KLOC and 5 people is _tiny_. C++ developers work at projects about 100 times that size and still beat the performance of Java easily. (Linux comes to mind. Firefox, Safari, Chrome. The various JITs are smaller, but still well beyond 50KLOC. Clang. Python.)
Sorry, Java has many advantages. Speed isn't one of them.
Java has many advantages, and speed is chief among them, but memory footprint certainly isn't.
And I'm not sure how you can say that the software you mention beats Java (let alone easily). You have nothing to compare it to. Those programs' requirements preclude Java before any speed considerations are taken. If you can't spare lots of RAM, and don't have the time to wait for the JIT to profile and compile your code, Java isn't for you. But if you just want speed for an always-online application - especially if it requires serious concurrency - I'd say Java would be a better choice than C++, performance-wise, 9 times out of 10.
If I were to pick an example to try and disprove my statement, I would actually choose Oracle or MySQL. But I don't know what requirements make them a better fit for C/C++ if, in fact, they are at all.
This is part of my problem, very few who don't have to confront the challenges or disadvantages of their technology of choice seem willing to acknowledge them.
That is a dire problem in what is ostensibly an engineering discipline.
We don't get to say concrete has higher tensile strength than steel just because we think concrete is the best thing ever.
That programmers can't even agree on basic notions of what's true does a lot to discredit our field.
Linux is written in C, not C++.
I'm pretty dubious, given that Google extensively utilizes C++ in their more performance sensitive portions of their architecture. Their custom web server, for example, is written in C++. Lets not forget the rather large HPC codebases out there in Fortran.
Can you prove any of this?
I don't know why Google uses C++, but I'd guess that it's for predictability. A web server would rather always have a reasonably low latency than somewhat lower latencies in most cases with a chance for an occasional latency spike.
Also, small, well-contained C++ program would probably perform better than Java, and I don't know how big is each of Google's C++ apps.
And like I said, this is very hard to prove; it's just been my experience after replacing a couple of legacy C++ apps with Java ones. But I think it could be "theoretically proven" (if that even means anything for such an empirical claim), by analyzing why and where C++ has any performance advantages vs. where Java has them, and showing that the larger the codebase and the team, the C++ advantages must disappear, while Java's become more significant.
Just to give two examples of why that should be: in a large application, the domain model might require some class methods to be virtual. The JVM can detect at runtime that in practice only one or two implementations are present, and would inline them. This is not possible for the C++ compiler. The other example is memory management. Java's memory allocation is so much faster than malloc (it's just a pointer bump), allows for better concurrency, and automatically reduces fragmentation. The way to get good memory management in C++ is by forsaking malloc for manual management (say, object pools), but that becomes increasingly difficult to maintain in a large, ever shifting codebase with many developers involved. Also, Java has better concurrency support which is, as you've said, important for throughput.
The only counter example is arrays of structs that are simply not supported on the JVM, and where C++ would have obvious cache-miss advantages.
NOT!