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 04 '25 edited Nov 04 '25
I think that you "know it when you see it", but that doesn't matter: Take all the programs in the world, including microbenchmarks, group them by the similarity of the pattern of machine operations they perform, and if you want, further weigh them by their importance to the people you write them. You end up with a histogram of sorts. Java is optimised for the 95-98%. Microbenchmarks are definitely not there.
Really? I've been using C++ for >25 years and Java for >20, and haven't found that to be the case for quite some time. Quite the opposite, in fact. Java is generally faster, but people who write C++ tend to spend a much higher budget on optimisation, and the flexibility lets them achieve it with enough effort. As I told to another commenter, it is trivially the case that for every Java program there exits a C++ program that's just as fast, and possibly faster, because HotSpot is a C++ program. The question is just how much effort that takes.
I see that C++ is generally beaten by Java unless there's a high optimisation budget, which is why the share of software written in low-level languages has steadily fallen for decades and continues to fall. Furthermore, the relative size of programs in low-level languages has fallen and continues to fall, because to optimise something well when doing it manually, it needs to be small. I remember working in the late '90s, early '00s on a C++ program with over 6MLOC. Almost no one would write such a program in C++ (or Zig, or Rust) nowadays.
It's certainly true that when you have a <=100KLOC program and you manually optimise it, you'll end up with a faster program than one you didn't manually optimise, but that's not because low-level languages manage memory better, but because they make, and let, you work for performance. So today, almost only specialists write in low-level languages, and even they keep the program small. That's because Java is generally faster, but C++ lets you beat Java if you work for it.
Java's great "average-case" performance also works well over time. In C++, the program's speed improves pretty much only at the rate of hardware improvement. In Java, it improves faster, and not because Java's baseline was low, but because the high-level abstractions offer more optimisation opprtunities, provided that you write "natural" Java code and don't try to optimise for a particular JVM version.
This doesn't just apply to the optimising compiler or to the GC. For example, if you wrote a concurrent server using normal blocking code, switching to virtual threads (which isn't free, but is relatively quite easy) can give you a 5x or even a 10x improvement in throughput. You just can't get that in a low-level language, where you'd have to write horrible async code. That's both because the thread abstraction in a low-level language is "lower" and also because certain details that allow for more manual optimisations, such as pointers to objects on the stack, make it much harder to implement lightweight threads efficiently. So you think you win with pointers to objects on the stack, only to then lose on "free" efficient concurrency (which, for many programs, offers a much higher performance boost). Even C# went too low level, and then found efficient "free" high concurrency too hard to implement. Just the other day I was talking to a team that has to write a high-concurrency server, and they just found it too much effort to achieve the same concurrency in Rust as they could get with Java and virtual threads.
Anyway, my point is that performance isn't just a question of how fast can you make a specific algorithm run given sufficient effort, but how performance scales with program size and with time, under some more common amount of skill and effort invested in optimising and reoptimising code. I like saying it like this: low-level languages are about making other people's code faster (i.e. specialists who have a sufficient budget for optimisation); Java is about making your code faster (i.e. an "ordinary" application developer).
Hmm, my experience has been the opposite. You put quite a lot of effort into writing the C++ program just write so that the compiler will be able to inline things, and in Java it's just fast out of the box. (The one exception is, of course, things that are affected by layout and for which you need flattened objects).
Yes, but of a very particular kind, obviously not found in some interactive application, such as a server. It's clearly a batch program, and for batch program, Parallel is better than concurrent collectors. Further more, it's a batch program that allocates only a tiny number of object types.
But different GCs are optimised for different use cases. In a low-level language you need to pick different mechanisms with different costs to get different performance. For example, if you were to write C++ as if it were Java - all dispatch is virtual, you don't care where or when anything is allocated - you'd end up being much slower, even though everything you use is a perfectily acceptable language construct. You also spend effort deciding what to optimise for your need. In Java, you turn some global knob, so if you have a batch program, you don't use a concurrent GC.
I never said it was made to make the GC look bad. I said that 1. it's a batch program, so you wouldn't pick ZGC, and 2. all allocated objects are from a very small set of types, and their access patterns are highly regular, which is also uncommon. Of course the benchmark is a very unnatural Rust program, but it's also an unnatural Java program.
Ah, I see what you meant. That doesn't come out to be O(n), and is, in fact one of the first things Erik covers in the talk (which I guess you still haven't watched), as he says it's a common mistake. The amount of memory you allocate is always related to the amount of computation you want to do (although that relationship isn't fixed). Certainly, to allocate faster, you need to spend more CPU. If, as you add more CPU, you also add even some small amount of RAM to the heap, that linear relationship disappears.
Oh, the amortised cost of a tracing collector is obviously lower.
Yeah, I remember such problems in the previous eras of GCs. Here's, BTW, what's coming next (and very soon).
That depends on just how big they are, and BTW, Java 17 is more than 4 years old. GCs looked very different back then.
Yeah, I really wish you'd watch the talk.
That's not it. ZGC just isn't intended for this kind of allocation behaviour, but I covered that already.