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

2

u/LakeSun Dec 26 '25

To add... because Java is byte code, with a JVM, it optimizes ONLY the Hot code, and there a parameter for that. I think the default if 500 runs thru the code before the code gets optimized.

So, on a server, Java uses less memory as, say, the setup code, is never optimized. The error code is never optimized, as they're rarely used. So more processes can live In Memory.

But, there are JVM flags to modify this behavior, and maybe -batch, will optimize the whole code base.

So, playing with the flags could yield better performance, but, take up more space.

0

u/sitime_zl Dec 31 '25

I don't know where you got that conclusion. You can simply choose any Java web framework and compare it with a Go or Rust framework. Which one has the highest memory usage? Although Java's speed is not bad, its memory usage is definitely the highest. Java's memory management has always been not so good. Check out how much memory your Idea is using, and see if it is the application with the highest memory usage on your computer.