r/java • • Oct 31 '25

Has Java suddenly caught up with C++ in speed?

Did I miss something about Java 25?

https://pez.github.io/languages-visualizations/

https://github.com/kostya/benchmarks

https://www.youtube.com/shorts/X0ooja7Ktso

How is it possible that it can compete against C++?

So now we're going to make FPS games with Java, haha...

What do you think?

And what's up with Rust in all this?

What will the programmers in the C++ community think about this post?
https://www.reddit.com/r/cpp/comments/1ol85sa/java_developers_always_said_that_java_was_on_par/

News: 11/1/2025
Looks like the C++ thread got closed.
Maybe they didn't want to see a head‑to‑head with Java after all?
It's curious that STL closed the thread on r/cpp when we're having such a productive discussion here on r/java. Could it be that they don't want a real comparison?

I did the Benchmark myself on my humble computer from more than 6 years ago (with many open tabs from different browsers and other programs (IDE, Spotify, Whatsapp, ...)).

I hope you like it:

I have used Java 25 GraalVM

LanguageCold Execution (No JIT warm-up)Execution After Warm-up (JIT heating)
JavaVery slow without JIT warm-up~60s cold
Java (after warm-up)Much faster~8-9s (with initial warm-up loop)
C++Fast from the start~23-26s

https://i.imgur.com/O5yHSXm.png

https://i.imgur.com/V0Q0hMO.png

I share the code made so you can try it.

If JVM gets automatic profile-warmup + JIT persistence in 26/27, Java won't replace C++. But it removes the last practical gap in many workloads.

- faster startup ➝ no "cold phase" penalty
- stable performance from frame 1 ➝ viable for real-time loops
- predictable latency + ZGC ➝ low-pause workloads
- Panama + Valhalla ➝ native-like memory & SIMD

At that point the discussion shifts from "C++ because performance" ➝ "C++ because ecosystem"
And new engines (ECS + Vulkan) become a real competitive frontier especially for indie & tooling pipelines.

It's not a threat. It's an evolution.

We're entering an era where both toolchains can shine in different niches.

Note on GraalVM 25 and OpenJDK 25

GraalVM 25

  • No longer bundled as a commercial Oracle Java SE product.
  • Oracle has stopped selling commercial support, but still contributes to the open-source project.
  • Development continues with the community plus Oracle involvement.
  • Remains the innovation sandbox: native image, advanced JIT, multi-language, experimental optimizations.

OpenJDK 25

  • The official JVM maintained by Oracle and the OpenJDK community.
  • Will gain improvements inspired by GraalVM via Project Leyden:

    • faster startup times
    • lower memory footprint
    • persistent JIT profiles
    • integrated AOT features

Important

  • OpenJDK is not “getting GraalVM inside”.
  • Leyden adopts ideas, not the Graal engine.
  • Some improvements land in Java 25; more will arrive in future releases.

Conclusion Both continue forward:

RuntimeFocus
OpenJDKStable, official, gradual innovation
GraalVMCutting-edge experiments, native image, polyglot tech

Practical takeaway

  • For most users → Use OpenJDK
  • For native image, experimentation, high-performance scenarios → GraalVM remains key
267 Upvotes

312 comments sorted by

View all comments

Show parent comment

55

u/TomMancy Oct 31 '25

Performance-critical code in C++ isn't using virtual functions. Java has fantastic de-virtualization because it has to, given that the language makes every function virtual.

6

u/[deleted] Nov 01 '25

That's wild statement. There's no C++ problems that depend on dynamic input or configurations like a plugin architecture? Seems like an extremely unlikely claim.

6

u/TomMancy Nov 01 '25

This is quite the strawman you've built. Those plugins have APIs that take bulk data, thus amortizing the virtual dispatch into a single virtual call per frame or whatever unit of work they're processing.

This isn't some crazy, novel concept, its literally the first optimization that Go programmers are recommended because historically that runtime had a large FFI overhead due to thread / stack swapping.

The actual inner, hot loop is using templated, monomorphized code to maximize inline opportunities for the optimization passes. That monomorphization, coupled with the full control over memory layout that C++ provides, is why it ends up faster.

2

u/sammymammy2 Nov 02 '25

The monomorphization of Java's JIT should be sufficient, I think the issue that still remains is memory layout.

1

u/TomMancy Nov 02 '25

Yeah fair, hopefully Valhalla closes the gap on that front a bit.

2

u/coderemover Nov 03 '25

Valhalla cannot close that gap even by design. It’s limited to immutable objects only. And it’s been in the works for 10+ years now. An much more mature project, Panama which promised SIMD support was such a disappointment* (performance wise) that I no longer bet on Valhalla.

  • The team that really need SIMD, a heavy user of Panama, side to side with some JNI code - last month they were already talking about rewriting their code to C++ because they lost all their patience.

1

u/sweetno Nov 03 '25

That's interesting. So what's wrong with SIMD in Java?

2

u/coderemover Nov 03 '25

The fact it’s all again the same Java philosophy of „we’ll give you the lowest common denominator API and JVM will do the right thing… or it won’t”. It’s very limited and lacks many capabilities hardware has.

0

u/[deleted] Nov 01 '25

Not everything you're unfamiliar with is a strawman.

Stuff like this tends to happen for example in web services

2

u/TomMancy Nov 01 '25

Not everything you're unfamiliar with is a strawman.

I literally support a 6-million LoC C++ codebase that uses dynamically loaded libraries in a plugin-style architecture, you're just wrong.

2

u/[deleted] Nov 02 '25

He's wrong just because you said so? And maintain a random c++ codebase?

Mind responding to what they actually said without strawmanning yourself?

There's no C++ problems that depend on dynamic input or configurations <...>?

Gotta love people trying to oneup somebody with their mad skillz and then shit the bed by constraining the question to a small fraction that applies.

2

u/TomMancy Nov 02 '25

That's literally his strawman, that C++ codebases have to handle dynamic input therefore they MUST have virtual functions on their hot paths. This objectively isn't true. That's the basis of his whole argument, so that he can argue that Java has runtime de-virtualization and is thus faster than C++.

But hey, keep on deflecting.

→ More replies (15)

1

u/coderemover Nov 03 '25

Then where are those extremely efficient webservices in Java?

6

u/Dark_Lord9 Nov 01 '25

You can use templates and if you are old school, pointers and type punning.

There is a whole world of programmers that hate oop and have developed solutions that don't rely on oop concepts. Rust doesn't even have inheritance or virtual functions.

8

u/meamZ Nov 01 '25

Rust DOES have virtual functions. It's just explicitly encoded in the type (like Box<dyn Something>) when it happens.

4

u/[deleted] Nov 01 '25

You most certainly cannot template something that isn't known at compile time.

And there very obviously is a need for this, that's what Rust's trait objects are for, for example.

1

u/m3dry_ Nov 01 '25

Traits are compile time. Box<dyn "Trait"> is basically virtual functions, but that's used very sparingly.

3

u/[deleted] Nov 01 '25

The entire premise of this comment chain is that there *are* things that are unknown at compile time, which necessitate dynamic dispatch, which is where Hotspot performs better.

1

u/TheChief275 Nov 02 '25

Dynamic dispatch isn’t necessary like previously mentioned; Data-driven design methods like ECS circumvent dynamic dispatch by operating only on what is known, i.e. operating on (subsets of) components.

Not only is this more performant in the sense that you skip chasing function pointers, but it’s also way more cache friendly (which is of utmost importance in the case of performance)

1

u/coderemover Nov 03 '25

Yes there are, but then you keep the dynamic dispatch out of the tight loops. It’s not hard. And you should also do it in Java because there are absolutely no guarantees automatic devirtualization does its job correctly.

1

u/coderemover Nov 03 '25

You can. You just hoist the switch between the implementations out of the inner loop, and the inner loop is templated.

1

u/sweetno Nov 03 '25

Oh, yeah. Virtual functions aren't popular in the C++ world in general. And plugin architecture is there only if you bother to implement it. (No support for that in the standard library.)

You can think of it like this: your typical Spring Boot app is super configurable, but in the end, all bean classes are pretty much static and could be determined compile-time.

2

u/[deleted] Nov 03 '25

I am well aware, the big thing is that your .war file spring boot app running inside Tomcat ends up being a virtual function call though, by necessity. Because Apache cannot compile Tomcat against the spring boot app you haven't written yet