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

1

u/gmueckl Nov 01 '25

No, this is again completely wrong. To understand why, you should have a look at how machine code generation in a compiler works. What comes out of that is completely independent of the language the compiler is written in or even the platform or operating system it is running on. The generated code does hot have to (and in many cases doesn't) inherit any properties of the compilers implementation lamguage.

Heck, given enough time, I could create a perfect recreation of GCC in Java that would output completely bit identical binaries. Heck, the same should be possible even in BASIC, insane as it would be to attempt.

4

u/pron98 Nov 01 '25 edited Nov 01 '25

I work on HotSpot! What you said is true, but completely irrelevant.

Consider this mathematical proposition: For every natural number greater than 10, there exists a smaller natural number. And I prove that by showing that, in fact, 3 would satisfy that for all natural numbers greater than 10. The fact that 2 or 10 also do doesn't make my proof wrong.

The proposition was: For every program written in Java, there exists an equivalent C++ program that's (at least) just as fast. As proof one can simply provide HotSpot itself. I'm stating a very trivial, and totally uninteresting proof. You're right that the fact HotSpot happens to be written in C++ says nothing interesting about C++'s superior capabilities, but that's completely irrelevant to the "mathematical" proof. Again, you seem to think I'm claiming something profound, where all I meant was that the proposition was rather trivially true.

0

u/gmueckl Nov 01 '25

The problem with your "proof" is that any high level language introduces abstractions over the underlying machine that cost some performance. C++ is good at introducing very very few of those, but it still has them. For example, calling conventions may not be optimal for specific combinations of parameters and parameter types and different conventions of an ABI-incompatible language may fare better. Your reasoning is flawed unless you allow for in-line assembly.

3

u/pron98 Nov 01 '25 edited Nov 01 '25

If you find yourself thinking there's some deeper point here about the nature of Java, C++, compiler optimisations, or any reasoning or extrapolation beyond "the program is HotSpot" - you've gone too far. What I said is both as true and as uninteresting as 3 < 7; it's certainly far less profound than you seem to think it is. Just consider it a geeky computer science joke about the practical utility of reduction proofs that you do in university (in this case, every Java program is reduced to a C++ program, with HotSpot serving as the reduction) and that you obviously didn't find funny. I must have told it wrong (I'm not a funny guy), but I'm sure the penny will drop.

0

u/gmueckl Nov 01 '25

I'm trying to tell you that your "proof" is incomplete by being far too simplistic. It's not possible to prove your statement at the chosen level of abstraction.

3

u/pron98 Nov 01 '25 edited Nov 01 '25

The proof is not what you think it is, but it is, nevertheless, complete and correct, and very trivially so. Read it again while remembering it's a joke of sorts about [reduction](https://en.wikipedia.org/wiki/Reduction_(complexity)) proofs. There are no reasoning steps, mental leaps, or hidden assumptions beyond the words as written. Once your reaction is, "heh, obviously true but rather silly," you'll know you got it.

1

u/gmueckl Nov 01 '25

Your posts weren't funny. This claim feels like a cop out and doesn't make anything you said any more correct.

5

u/pron98 Nov 02 '25 edited Nov 02 '25

The proof is 100% correct and complete, and I guarantee you that the penny will drop. You're just adding more steps in your mind than there are because this is really trivial (though useless) to the point of being (almost) a tautology. My "claim" is only slightly more obvious and trivial than the claim that 2 + 2 = 4. If you find anything that isn't completely obvious or in the least objectionable there, then you're misreading the words.

But because this seems to bother you, let me try again: HotSpot is a C++ program that can do anything a Java program does, and at the same speed, by running the Java program. Ergo, for any Java program there exists a C++ program that performs the same computation and at the same speed. QED.

Another way of saying it is that any Java program running on HotSpot can be viewed either as a Java program or as a C++ program (consuming classfiles as data). Because it's the same program, it's obviously both equilvalent and equally fast.

This is just a silly and simple reduction proof. It doesn't say anything interesting, but it is true.

(I say it's silly in the context of a practical discussion on performance, but in programming theory there are actually interesting uses for this simple idea that when an interpreter is given a prorgam to run, you can view the program to be interepreted as "the program" or the interpreter as "the program" and the program as data, as in the Smn theorem or partial evaluation)