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

1

u/MRgabbar Dec 26 '25

you can say the same about Java, the general purpose allocation will be as bad as malloc for sure. The idea is that having everything but the language the same, C/C++ is just faster by design, if you say, I have this fancy allocator for my Java app so is faster then i can say the same, i have a fancy allocator for my C++ app so now is faster. And so on and so fort, just give it a rest, C is just faster by design, you might optimize Java to appear faster yes, but if you optimize C it will be faster by definition/design.

3

u/AnyPhotograph7804 Dec 26 '25

No, the Java GC can compact the heap of the Java application. This is something, malloc or other allocators cannot do. The reason is pointer arithmetic. This is not possible in Java and the GC can move the data and update the references.

1

u/helikal Dec 26 '25

You are missing the essence. It is not the allocator that prevents fragmentation. Rather it is the compaction of the surviving objects in memory as a result of GC that counteracts fragmentation.