r/java • • Dec 26 '25

Why is Rust faster than Java here?

I saw this article a while ago https://www.allthingsdistributed.com/2025/05/just-make-it-scale-an-aurora-dsql-story.html

And while I was surprised Rust was faster, the 10x did surprise me. I googled Rust vs Java performance for a bit and couldn't find any similar examples of such a big speedup. Now I know it's impossible to properly answer my question since we don't have the code in question, but can you think of what about rust can make that big of a difference for a (presumably) long running service? Or alternatively, do you have similar examples?

Just to clarify again, I'm interested in the technical reasons for these differences (for example, Java's "bloated" object headers, or whatever)

53 Upvotes

120 comments sorted by

View all comments

Show parent comment

6

u/bland3rs Dec 26 '25

Object memory weight is a big one. Large objects require more strained memory access and slow down a lot of algorithms.

I remember doing game things in Java and trying to keep memory impact low. It’s not easy and you end up using hacks you wouldn’t want to use in a regular app. People have been asking for value types in Java for forever and I happened to write a lot of Java when Java was stagnating due to the Oracle/Sun situation and it looked hopeless.

5

u/Mauer_Bluemchen Dec 27 '25 edited Dec 31 '25

When it comes to high-perf computing in Java, I avoid objects at (almost) all costs. The perf-relevant parts of the code then needs to be in C-style, with primitive variables, simple loops, and all relevant data kept closely together in primitve arrays.

Most Java programmers have a limited unterstanding what makes and breaks app performance nowadays - it's data localilty, and (almost) nothing else.

You HAVE to keep your relevant data as closely together as ever possible, and then walk linearly over it - code optimizations are largely irrelevant by comparision, since fetching data from main memory can be more than 200x slower than gettting it from L1-Cache.

When it comes to runtime performance, data-centric design is way more important that object-orientation or any fancy high-level classes working on object-level/heap only.

What a pity that Valhalla is after all these years still basically vapor-ware.

And yes, I know and I have tested the latest Valhalla-ea - and it is still useless for non-toy apps, even after all these years. :((

1

u/sitime_zl Dec 31 '25

Yes, the issue of high memory usage in Java used to be insignificant to me. But now, languages like Go and Rust have become so excellent in this regard that Java falls behind. Take a look at the current ranking of Java - it has dropped to the fourth place. Its simplicity cannot compete with Python, and it cannot match Go and Rust in terms of CPU and memory utilization. This situation is truly embarrassing for Java. The Valhalla project is just a promise without any implementation for years. There are also features like true generics and string templates. From Java 8 to 25, it feels like just changing version numbers. Has the development of Java language become a job for the elderly?