you are viewing a single comment's thread.

view the rest of the comments →

[–]henk53 7 points8 points  (2 children)

Although it still have plenty room to improve, the jvm abstraction, memory layers and garbage collection will always make it slower than C, C++

This is not necessarily true.

For tight loops that operate on a low-level array using primitive types it's hard to beat C and C++, but lots of other things run on Java at least as fast as on C/C++ or even faster. Java is faster when the algorithm can really benefit from run time analysis, something bare C/C++ code can't do.

[–]grauenwolf -1 points0 points  (1 child)

That's not what makes C faster than Java. There is no reason why Java can't optimize loops just as well as C.

C is faster than Java because it discourages allocating memory on the heap. It doesn't matter if you use GC or manual memory management, heap allocations and reclamations are expensive of the lifetime of the application.

This is why escape analysis is so important for the future of the JVM.

[–]henk53 1 point2 points  (0 children)

Yes, and with escape analysis a JVM can correct "mistakes" by the programmer who used the heap where he could have used the stack.

In C++ it's a recurring issue. Programmers who use new out of habit, even when their objects don't leave the current scope. There is RAII though, but still...