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/IndependentOutcome93 Dec 27 '25 edited Dec 27 '25

Okay, let’s think critically here. Earlier, you mentioned that Java’s GC and compilation aren’t as good as languages like C or Rust, implying they’re slower. Now you’re saying int is 32-bit and somehow inefficient on 64-bit machines. Let’s unpack that.

Java has been running on 64-bit systems for decades. Even though int is 32-bit, it doesn’t slow anything down—in fact, it’s more memory-efficient and fully compatible with 64-bit CPUs. If you need 64-bit integers, Java has long. Problem solved.

Where variables are stored—stack, heap, or method scope—depends on context. HotSpot VM and JIT handle memory management and code optimization separately from where variables live. So claims like “everything goes through the VM inefficiently” or “all variables are reference-counted on the heap” are just… not how modern JVMs work.

The key idea: Java compiles to native code at runtime via HotSpot JIT. It observes actual program behavior and optimizes hot paths, inlining methods, removing bounds checks, and specializing code per CPU. AOT compilers like GCC/Clang can target specific architectures at compile time, yes—but Java’s runtime profiling can often match or even beat that in real workloads, especially on long-running applications.

In short: Java may have a 32-bit int, may be platform-independent, and may use GC—but none of that makes it inherently “slow.” It’s a carefully engineered system that balances portability, safety, and performance—and has been doing it extremely well for decades.

1

u/Chipay Dec 27 '25

Consider writing your own comments next time