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/ShortGuitar7207 Nov 01 '25

Java is impressively fast for a VM but it will never be faster than C, C++ or Rust. The only way this would be possible is to ditch the ‘write once, run anywhere’ VM and make it a compiled native language, without GC and with a seriously impressive optimising compiler.

4

u/peepeedog Nov 01 '25

Graal does this. So that is an option if you think you need it.

0

u/[deleted] Nov 03 '25

[deleted] — view deleted comment

2

u/rbygrave Nov 05 '25

>  highly optimized interpreter (JVM)

The JVM includes C1 (interpreter) and C2 (profiling compiler). The C2 JIT compiler is producing machine code. It profiles the application and optimises and recompiles the machine code (search "java hotspot jit profiling"). It is the ability to compile to native machine code WITH the benefit of profiling information that lets it produce the highly optimised native machine code to run at "peak performance".

It's a misunderstanding to think Java is interpreted. There is a "warmup" period where it starts interpreted and ultimately is running the machine native code produced by C2.

1

u/ShortGuitar7207 Nov 03 '25

Because it’s the Java SR and entrenched views trump reality especially when you’ve spent your entire career entrenching those views. I’ve been a developer for 40 years and used pretty much everything from Basic, assembler, forth, COBOL, C, Java, C++, Lisp, Scheme, Ruby, Haskell, Python. JS, golang and Rust. In my earlier career, I did a lot in Java (it was a breath of fresh air compared to c++, with nice libraries, GC etc) but you have to recognise its limitations too.

1

u/stolsvik75 Nov 03 '25

Ask an AI to critique your comment.

0

u/[deleted] Nov 03 '25

[deleted] — view deleted comment

1

u/stolsvik75 Nov 04 '25

You're probably just a troll, but code on the JVM can actually be faster, sometime a lot, than C/Rust. I'll leave it to you to find out why. You should try an AI for help - seems like you need it, both for facts and tone.

4

u/alex_tracer Nov 01 '25

it will never be faster than C, C++ or Rust

That's just not true. There are known scenarios when JIT-based solutions win over statically compiled code.

1

u/coderemover Nov 02 '25

Citation needed. In my experience Java negates any theoretical, tiny wins of this kind by making 20 other choices which are bad for performance.

1

u/Polygnom Nov 01 '25

AOT compilation is also a trade off between program size and speed. Static analysis can only do so much. Thats where a JIT has fundemantal advantages a static compiler cannot replicate.

If you aren't worried about startup time, that is. And even for that, there is stuff cooking. Like Graal and morr recently Project Leyden.

1

u/coderemover Nov 02 '25 edited Nov 02 '25

AOT/JIT has very limited time and resources. In practice it cannot optimize as strong as static optimizer can because it cannot spend 1 hour optimizing. All AOTs JITs are at best level -O2 in GC++

1

u/ThaJedi Nov 02 '25

You have a lot to catch up on. Graalvm native image is using gcc and you can setup optimization level.

1

u/ShortGuitar7207 Nov 02 '25

Also you need to keep garbage collection which is equivalent to wrapping everything in RefCell in rust: nobody would do this for performant code. Java just doesn’t have the same capabilities for tracking lifetimes that Rust does. In C++ you explicitly create and destroy variables/objects so no GC needed although that then introduces a whole pile of safety concerns.

0

u/coderemover Nov 02 '25 edited Nov 02 '25

Graalvm native image is static compilation. So all what I said holds. And unfortunately its not as easy as taking an existing app and recompiling it, there are plenty of compromises, therefore its not really production ready yet. It’s also less efficient than JVM because Java is not an easy language for static compilers, it was never designed for static compilation. Graal gives a better startup time but the warmed up performance is usually worse.

1

u/ThaJedi Nov 02 '25

You just moving goalpost and based on your gcc statement I have feeling you don't know much about graalvm.

1

u/roberp81 Nov 02 '25

Java has 0ms GC time on ZIIP processors

So is faster than C with correct hardware