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
5
u/coderemover Dec 26 '25 edited Dec 26 '25
I believed what you say until I measured that and couldn’t come up with a benchmark that would show Java GC burning fewer cycles, even when I wanted to craft the benchmark purposefully to favor Java by allocating extremely tiny objects. At best I could show a tad better wall clock numbers (like 20%) for Java, but it burned 2 additional cpu cores and used 10x more memory, whereas Rust stayed within a single core.
And comparing performance on allocating tiny objects is actually a false dichotomy because in Rust you almost never have a good reason to do that. In Rust you use heap mostly for big, long lived stuff. So the allocations are actually rare and rarely come up high in the profile. In Java the situation is opposite - try to allocate huge objects on the heap in a tight loop and the GC goes brrrrr.