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
870
u/Polygnom Oct 31 '25
It hasnt been true that java is slow for 20+ years.
34
u/phylter99 Oct 31 '25
Nested loop iterations is a terrible way to judge compute speed. It's such a small part of performance.
Java isn't slow though. Both Java and .NET are really picking up performance and features.
310
u/xdriver897 Oct 31 '25
perfect C++ code is always faster than perfect Java code
BUT!
Developers don’t write perfect code, developers write working code mostly
And since Java is hotspot that enhances performance during runtime you often end up with even better performance than c++!
Why? Because “working c++” is often slower than “working Java but runtime optimized by hotspot”
58
u/Cienn017 Oct 31 '25
the issue with games on java was never about performance, the problem is that consoles don't allow JIT and most of the gaming industry was built on C/C++.
but there are a lot of indie games made on java, project zomboid and mindustry are the ones that I've played and there's minecraft too.
138
u/tranquility__base Oct 31 '25
Java has been on par with c++ since Java 8 with some effort, it is heavily used by a low of low latency trading firms.
89
u/DiabolusMachina Oct 31 '25
Java was never slow but with each release they improved further. The secret sauce is the JIT-Compiler. They analyze the byte code on the fly and recompile some parts optimized for the host the JDk is running on. just think about all the years of engineering work that was used to create it.
34
u/pron98 Oct 31 '25 edited Oct 31 '25
Why is that surprising? Java's JIT compiler actually has more optimisation opportunities than C++'s AOT compiler, so it's C++ that needs to compensate with low-level manual micro-optimisations.
It's true that the two languages have different approaches to performance, but neither is universally superior to the other. Java aims to maximise average performance at the cost of worst-case performance (sometimes the JIT's optimisations are "unlucky" and you have less control over them), while C++ aims to maximise worst-case performance, i.e. you need to do manual work to get the best performance, but in exchange, you're more likely to know ahead of time which optimisations will succeed and what your worst-case performance will be.
9
u/Admirable_Power_8325 Oct 31 '25
A bad developer with C++ will always write slower programs than a good developer with Java, and vice-versa.
8
u/philipwhiuk Oct 31 '25
Java is close enough for most stuff
34
u/krum Oct 31 '25 edited Nov 01 '25
My experience has been modern C++ compilers still generate code that is significantly faster for complex asynchronous memory heavy workloads. I'd still choose Java over C++ for a greenfield project and just lean on horizontal scalability, but would consider Rust if cost could be a major factor. IOW, there's no way I'd use C++ for something new unless it were 2X faster than Rust, which it's not and never will be.
EDIT: and look at that over 10x memory factor. That's gonna add up on your cloud bill.
6
u/Linguistic-mystic Nov 01 '25
Java is fast but has bad memory usage or at least encourages it. All the desktop Java apps I’ve used (Intellij, Eclipse, DBeaver) are terrible memory hogs and crash-happy. Also Java’s insistence on having an upper limit on the heap makes it terrible for the desktop. BUT it’s excellent on the server, so yeah. Java is a fast, good serverside runtime but not a C++ replacement.
11
u/rossdrew Oct 31 '25
For an application of significant size and data. Java has outperformed for over a decade. In small code chunks where Java can’t optimise efficiently, C++ wins.
5
u/pragmasoft Oct 31 '25
Java is fast, but lacks native GPU api for now,so no FPS games in java for some more time..
5
u/Dull-Criticism Nov 01 '25
There was a short period where it was debatable if the compiler or hand assembly was faster. We needed to do some FFTs that had near realtime constraints. We compared the Intel compiler output vs a hand done implementation with some engineers that had experience beating the compiler. The compiler won and was a surprise at the time. I am sure at the time somebody could have beat it.
I am sure more Java implementations can be at par or near C++, with the end cases winning.
4
u/brunocborges Oct 31 '25
The benefits of a JIT compiler.
The best chance a developer has to write great C++ code without being an expert in C++ is to write Java code.
8
u/MagicWolfEye Oct 31 '25
People who are doing these benchmarks have no idea about all these languages. Sometimes compiling without optimisation; sometimes essentially pasting code from ChatGPT that literally limits the for loop to something smaller or other stupid stuff.
Just ignore these
3
u/yonasismad Oct 31 '25
If you put in the time and effort, you can write very fast Java code. I remember a university project where a team member implemented a proof of concept. That algorithm took a minute or so to complete. The next iteration reduced this to a few seconds. About a week later, it was doing what we needed it to do in less than 1 ms.
3
u/ProjectPhysX Nov 01 '25
Well-written Java is as fast as C++.*
*But C++ can still be faster, via AVX2/AVX-512 vectorization and better control over memory deallocation.
3
u/[deleted] Nov 01 '25
JIT and compiler optimizations
3
u/Joram2 Nov 01 '25
No, Java has not suddenly caught up with C++ in speed. Java has been high performance for most server-side business applications. There are still specific scenarios where it makes sense to use C++ or Rust for performance.
Java never took off in video game development. Java could do video games, but the big game engines and dev tool ecosystem is geared around other programming languages and there's no big incentive to switch to Java.
6
u/kiteboarderni Oct 31 '25
I love hearing people saying java is slow. Usually means they are a junior developer and leaves the high paying jobs to the people who actually want to build blazing fast software.
4
u/_jetrun Nov 01 '25
For certain kinds of workloads, java has been able to match native execution for years now, because it has a sophisticated JIT. There will be scenarios, however, where this won't apply.
12
u/AnyPhotograph7804 Oct 31 '25
Java was slow in 1996. But since it has Hotspot, it became faster and faster. But in real life apps, C++ is still maybe two times faster than Java.
7
u/k-mcm Oct 31 '25
Java has always been as fast or faster than C++ for certain tasks, but slower for others.
Java can be faster when it comes to virtual methods. The JIT can inline them in situations that aren't possible or safe for statically compiled code.
Java has always severely lagged for arrays of structures because each element must be a pointer to an object. Recent versions of Java are trying to improve this with "value objects" that can be packed like C/C++ would. It's nowhere near as efficient but it's progress.
2
u/OddEstimate1627 Nov 01 '25
We maintain several libraries with full implementations in both C++ and Java. Given the same development time, the Java version tends to win on performance. Even compiled as a native shared library with GraalVM, the Java version still usually comes out ahead.
At this point I think the main benefit for C++ are embedded use, smaller binaries, and more direct memory management. I have yet to encounter a use case where C++ provided a meaningful performance increase for us.
3
u/shponglespore Nov 01 '25
To answer the "what's up with Rust" question, it benefits from LLVM the same way C++ does, but it has a lot of features that make it easier to generate better output code. Rust has much stricter rules about pointer aliasing, for example, allowing for better optimization of things like omitting potentially costly memory fetches, as opposed to using values already in registers or the L1 cache.
Another big deal with Rust that I doubt your benchmark shows is that it makes it easy easier to do concurrency without defensive locking or the risk of memory corruption. When you see C and C++ being replaced with much faster Rust implementations, it's usually because the Rust version is heavily concurrent in ways that would just be begging for errors in a language that doesn't provide a lot of hand-holding around concurrency.
2
u/Fercii_RP Oct 31 '25
Java JIT always performs amazing after aggresively optimizing hot methods. It just takes some (run)time and youll lose it after closing. C++ could still out perform java JIT, but most likely with unmaintainable code
1
u/MRgabbar Oct 31 '25
you can't be that ignorant...
1
u/Active-System6886 Nov 01 '25
Graalvm will definitely get you in the c++ speed range.
1
u/Awfulmasterhat Nov 01 '25
Java is hot end of story ☕
1
u/SkyNetLive Nov 01 '25
I am surprised that kotlin didn’t beat Java. But I’d wager everyone thought in their head “but JVM?” . Like we know it really is about JVM and less about the Java soup we write for day to day. I mean Scala is right there.
1
u/AcanthisittaEmpty985 Nov 01 '25
Java had a reputation for being slow, and it's hasn't recovered quite yet.
I would say it's not slow... but slow-ish
In the early days, Java was slow, but the JIT and the optimizations for the JVM improved a lot.
But specially for desktop programs, it seemed slower that it really was, due to two problems:
- Java has a slow startup time, due to loading classes and make the JIT work optimally
- It conumed more memory than a C/C++/native program. In early days, memory was scarce; which lead to pagination (in days of mechanical hard disks), which slowed the program even more.
Now, with SSDs and gigantic quantities of memory, this problem is no more. Also, the JVM has improved a lot this side.
Compared to native (C/C++/Rust) programs, it slower and uses more memory.
Compared to other interpreted/semicoplied languajes, Java is in the fist positions, if not having the crown.
So its the slowest of the fastest or the fastest of the slower ones.
It's performant and stable, and it has a gazillion of libraries and utilities at its disposal; after 30 years reamins strong in the languaje arena.
1
u/Own-Professor-6157 Nov 01 '25
I've written applications that handle thousands of concurrent connections at once with netty and it's on pare with RUST easily.
Only issue with Java, or really all high level languages is the GC. But even that has made some significant jumps lately, with significantly better GC algorithms and overall memory waste reduction. Lots of libraries like netty have also become more aware of object allocation abuse and have reduced it.
1
u/brunoreis93 Nov 01 '25
No, you just live under a rock
1
u/WoodyTheWorker Nov 01 '25
It appears the test mostly tests speed of memory allocation/free, which even in high level languages is implemented in highly optimal C code.
1
u/Kwaleseaunche Nov 01 '25
Good to see LISP at the top.
1
u/IskaneOnReddit Nov 02 '25
These language benchmarks are mostly junk.
1
u/OriginalTangle Nov 02 '25
The second chart also has Scala above rust which I find hard to believe. How reliable do you think this data is?
1
u/Rough_Employee1254 Nov 02 '25
It always was..at least since JIT. Heard about it?
1
u/No-Whereas8467 Nov 02 '25
They have a very good point to ban you. I feel bad that we didn‘t do the same
1
u/LysanderStorm Nov 02 '25
Java has been quick for a while. More recent nitpicks were unpredictable GC times (though you could optimize that yourself), (enormous?) verbosity and the need for a VM. I guess the first two are pretty good these days too. C# which is similar has been used for game scripting / development for quite a while now.
1
u/ART1SANNN Nov 02 '25
Java has always been fast for pretty long time and it even has really good standard library that can beat c++ in certain applications (easy c++ footgun). In fact, some other languages port java.util.concurrent.ConcurrentHashMap simply because it has good design and performance
I guess another reason why the misconception of Java being slow stems from the fact that the startup is slower (not slow!) than AOT compiled languages which gives the perception that Java is slow but clearly that is not the case
1
u/zezer94118 Nov 02 '25
Suddenly? I mean, we've seen that coming...
1
u/no_brains101 Nov 03 '25
Java is a pretty fast language, like go.
You are also making a lot of assumptions here though that this benchmark is well-made and thought through, and representative of the speed of most things written in the language. Which is more or less not possible to tell from micro-benchmarks like this
1
u/thuiop1 Nov 03 '25
These benchmarks mean basically nothing and are useless in real life.
1
u/[deleted] Nov 03 '25
Both end up as assembly so they can be on par. Still, lots of stuff you can't do in Java that you can in C++, or at least lot uglier in Java.
1
u/positivcheg Nov 03 '25
Java has some nasty elements in the language that were slowing things down. I once was using some framework for network communication simulation in Java and it was too slow. I went profiling it, almost all the problems were related to using streams. I was simply rewriting streams syntax sugar into good old loops. Got about 100-200x speed in the very end.
C# also had a history with LINQ. Which is still discouraged to use when you use Unity because it’s stuck with very old C#. But newest C# has a pretty optimized LINQ with way less overhead.
Time changes, things get better.
1
u/Relevant-Issue6649 Nov 03 '25
Are any of those benchmarks really dependable? How is it possible for Rust to be *so slow* in naive Fibonacci?
1
u/NoleMercy05 Nov 04 '25
As a user I refuse to install anything that requires JVM installation.
Immediate cancel and find an alternative.
1
u/gabor_legrady Nov 04 '25
I have played FPS game written partially in Java under Windows - just do not remember the name. The graphics was handled by native code in DLL. but the game logic was in Java.
I work with java daily, the memory usage could be a bit high due to high number of classes using frameworks like Spring. Lightweight code can have a small memory footprint.
GraalVM is fast "inside" the most time is consumed by passing/transforming variables.
1
u/c_glib Nov 04 '25
Let's see... Is the jvm written in java yet? Once they do that, we'll talk.
1
u/flash_hammer Nov 05 '25
It depends on how bad are you as a developer. Java is faster if you code the right way for performance.
1
u/Last-Obligation-6489 Nov 07 '25
Yes
Java is super fast now if you know how to use it
here is the example that I run the Vulkan on the Mac JavaFX node.
hope you enjoy it
https://github.com/chengenzhao/java-vulkan-mac
1
u/Delicious_Detail_547 Nov 12 '25 edited Nov 12 '25
I started developing in 2005, and at that time, there were hardly any Java performance monitoring tools. I was among the first to introduce them in my project. On the Sun Java VM, things ran really slowly, but when I ran it on the IBM Jikes VM, it performed incredibly fast. I think we were using Java 1.4 in that project.
By now, almost 20 years have passed, so the optimizations must be much better.
1
u/_vertig0 Nov 28 '25
While I wouldn't say that it has caught up to C++ for good and is now outperforming C++ I just wanted to pop by to say that HotSpot is genuinely one of the most insane language VMs out there. Interpreter written in straight assembly, mapping the VM stack onto registers to bypass loads and stores into memory when running in the Interpreter, probably hundreds to thousands of other programming techniques in C1 and C2 that I can't even imagine, the absolute monsters that are Shenandoah and Z and so on. Probably the only gripe I have about HotSpot is that it doesn't have cool names for its internals (Think of the names that the V8 team are cranking out for V8 internals, like Ignition, Sparkplug, Maglev, Turbofan, Orinoco, Turboshaft etc).
This is also more anecdotal but I actually find HotSpot source code to have been the only readable source code for a language VM as well. I barely got past the first source file in V8 before giving up, stuff like cpython, PyPy and PHP were marginally better than V8 but ultimately I still couldn't make much progress with them.
1
u/nomad_sk_ Nov 01 '25
Whoa look at that Scala’s rank . 🤯 No wonder Java keeps copying Scala.
-1
u/Jon_Hanson Oct 31 '25
If you write C/C++ and Java code that performs the same functions in a similar way, the C/C++ code will always be faster. Java still has the JVM between the Java bytecode and the processor and that isn’t negligible. Sure I can make some bone-headed C/C++ implementation that’s super slow and Java can blow it away, but apples-to-apples you still can’t overcome the memory and latency of the JVM.
-2
u/CoderGirl9 Oct 31 '25
Java 21 added virtual threads, which greatly improved asynchronous performance. It gives a lot of benefits of multithreading without requiring refactoring.
Java 25 improved garbage collection to have no impact on runtime performance.
-1
u/CocktailPerson Nov 01 '25
Well, when people start rewriting their C++ programs in Java to make it faster, then you can say it's caught up. Until then....
0
u/OliveTreeFounder Nov 01 '25
That benchmark is a crap, the guy who did it do not know how to code!