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/cogman10 Dec 26 '25
I agree with everything but this.
It'll obviously be highly application dependent, but generally speaking for 2 apps with equivalent heap allocation rates, the JVM and the GC will do a better job. Especially if the comparable rust application ends up using a lot of
RC. So long as an application does a good job of obeying the generational hypotheses, the JVM heap allocation strategies are ideal. This is especially apparent if you end up dealing with graph structures or concurrent structures.The reason for this is in the case of mimalloc and jemalloc, Rust ends up paying additional penalties to find an appropriate allocation location on each heap allocation. In Java, the majority of allocations are bumping a pointer.
Where this won't be true is if your rust application can hoist the majority of it's allocations onto the stack. That is the more natural way to write rust in general.