Remix.run Logo
▲ nnevatie 2 hours ago

> Java

Well, there's your first problem, when it comes to performance. Let's not kid ourselves - JVM is great, but it doesn't hold a candle to optimized native code.

▲pjmlp an hour ago | parent | next [-]

It works great for Amazon and Netflix, some people can, others don't.

▲trickypr 2 hours ago | parent | prev [-]

I don’t think this is fair? Java isn’t that slow, so long as your task isn’t long running (give JIT time to get going) and isn’t doing anything insane like reflection.

I don’t doubt that the C++ code base may end up faster, but probably because tangential optimisations (like the author’s lock free programming, or more intelligent memory allocations) rather than because the same code runs significantly faster.

▲cpgxiii an hour ago | parent | next [-]

The biggest difference is that you would not be writing the same code in both Java and C++. It's an exaggeration, but writing "Java in C++" would be passing every non-trivial parameter as a shared_ptr. Of course no one in the C++ community would think this was a good choice, and you generally only ever encounter ownership this messy in really old or weird libraries. The language simply gives you more ways to express ownership and memory layout/locality in idiomatic ways, whereas achieving similar behavior in Java is much less trivial. For nontrivial programs, memory layout and locality has a very significant affect on performance; rarely are you going to have a program that spends all of its time bound by ALU/FPU performance (but when you do, that control over layout means C++ has long had very capable libraries for SIMD math, where adding it to managed languages has been a much more recent addition).

Really the only thing that's well known to (potentially) be faster in Java is certain lock-free datastructures where the JVM GC essentially allows object cleanup to be trivially deferred out of performance-critical points. You can do the equivalent of this in C++, but it generally requires care and it looks very weird.

▲pjmlp an hour ago | parent [-]

Java is 1990's C++ way of programming, thus it isn't writing Java in C++, it is writing C++ just like the community was doing with OWL, VCL, PowerPlant, CSet++, MFC, Motif++,... before 1996.

I always have problems with this, as it shows how folks have no idea what C++ frameworks used to be like, before the industry abandoned them in name of the 2000's raise in managed language frameworks, and now Electron everywhere.

All those J2EE, ASP.NET, Swing, Forms, Django, Rails and co, had some kind of C++ predecessor.

▲Narishma 2 hours ago | parent | prev [-]

One place where it's definitely worse than C++ is memory usage.

▲pjmlp 40 minutes ago | parent [-]

Depends in the C++ skills, and how the code looks like, from "C with a C++ compiler" up to "worthwhile of a CppCon talk".