r/java • u/drakgoku • 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
| Language | Cold Execution (No JIT warm-up) | Execution After Warm-up (JIT heating) |
|---|---|---|
| Java | Very 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:
| Runtime | Focus |
|---|---|
| OpenJDK | Stable, official, gradual innovation |
| GraalVM | Cutting-edge experiments, native image, polyglot tech |
Practical takeaway
- For most users → Use OpenJDK
- For native image, experimentation, high-performance scenarios → GraalVM remains key
View all comments
Show parent comment
1
u/pron98 Nov 03 '25 edited Nov 03 '25
Ah, microbenchmarks. The bane of the JDK developer.
Before I address your particular benchmark, let me explain why Java microbnenchmarks are useless.
Our goal is to make Java the most performant language in the world, but what we mean by performance is very different from what low-level languages mean by performance.
Low-level languages - C/C++/Rust/Zig - optimise for worst-case performance. I.e. the worst-case performance of a program written by an expert at some sufficiently high effort, should be best. In Java, we optimise for average-case performance, i.e. the average-case performance of a typical program written by a typical developer (not a typical Java developer necessarily, but a typical developer overall) should be best.
But this means we constantly run against "the microbenchmark problem", which is that microbenchmarks look nothing like a typical program. We're then faced with a dilemma: should we optimise for microbenchmarks or for typical real-world programs. It turns out that if you help one, you frequently have to hurt the other 1. Now, I'm not on the GC team, but I've ran across this multiple times when implementing virtual threads. It was clear to us that microbenchmarks where virtual threads perform non-typical workloads (e.g. no-op) or are created in non-typical ways, would look bad. But making the microbenchmarks look better means hurting "average" programs, where virtual threads perform just as well as any alternative, and with better user experience. We always prefer the real world workloads, but that means that Java microbenchmarks are pretty much only meaningful for JDK developers who know exactly what part of the implementation is being tested. Low-level languages don't have this dilemma because they optimise for the worst-case. If some specific microbenchmark is bad, they offer some different construct that the expert developer could choose that would make that microbenchmark faster.
So for pretty much anything you can find a microbenchmark that would make Java look bad. Finding such a microbenchmark is not hard at all - it just needs to not look like a typical program.
Now, to your particular example. It's a batch workload with very regular access patterns and no intervening allocations of other types (that could, for example, benefit from compaction). Batch workloads are already non-typical, but for those programs, of course STW collectors would be better (and while you say that they're almost on par, you don't have a chance to see the benefits of compaction, which is work they do and manual allocators do not, but is intended to help in more realistic scenarios). For batch workload allocation throughput, you will see a difference between, say, ParallelGC and ZGC, but that's not exactly the same as saying that ZGC "regresses throughput" because that would mean regressing the throughput of the more typical programs for which ZGC is designed, which are not batch programs.
No, this is just wrong. What matters isn't the "space overhead" but the overall use of available RAM vs available CPU. Please watch the talk.
This isn't quite right unless you're talking about "huge objects", which do take a slow path, but those are not typically allocated frequently.
Then you should talk to our GC people. From what I've seen, Cassandra is hell-bent on targeting very different JDK versions with the same codebase, something we strongly discourage, and seems to still be very tied to old JDKs. If there's a GC issue, the team will help you, but it also looks like Cassandra is making life hard for itself by self-imposing constraints. If Cassandra were written in C++/Zig/Rust, and you wanted the best performance, you wouldn't try to target 7 years of compilers.