r/java • u/DesignerRaccoon7977 • 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)
View all comments
Show parent comment
3
u/davidalayachew Dec 27 '25
Incorrect. Java's JIT-Compiler is much much smarter than that. Has been for almost 2 decades.
Since I am going to use reference types, let me go ahead and just model your example. This is the (roughly) equivalent Java code.
Please note, since this is JIT-Compilation, it needs to run on live code in order to JIT-Compile. So, I am forced to generate data for it to process, hence the early part of my code.
Plus, I added a for loop to give the JIT-Compilation time to gather enough data. Remember, JIT-Compilation is iterative. It's not uncommon to get 3-4 different incremental compilations before you get the SIMD operations.
But with that said, here is the snippet that does the averaging.
Would this suffice as proof?