Published on

What Rust Taught Me About Performance That Java Hid From Me

My professor kept saying Rust is a beautiful language. It doesn't do things for you automatically, he said. If you want something, you have to say so.

I liked that idea. Then I started writing Rust, and it turned out Rust does plenty for me. It fills in types I never wrote. It converts some references for me without my asking. It cleans up memory when I'm done with it.

So for a while, I thought he was just being romantic about the language.

What Rust automates, and what it doesn't

Then I noticed a pattern. Everything Rust does for me is either free or happens at a point I can see.

It will fill in a type for me, because that costs nothing at runtime. But it won't quietly copy a large piece of data. If I want a copy, I have to write .clone(), and it sits right there in the code. It won't quietly convert one number type into another. And there's no garbage collector deciding when to pause my program. Memory is freed exactly when the variable goes out of scope.

The rule, as I see it: Rust saves you typing, but it never hides the cost.

That's when "beautiful" started to make sense. It's not that Rust does nothing for you. It's that nothing important happens behind your back.

Where Java hid it from me

Java makes the opposite trade-off. It decides the expensive things at runtime: when memory gets cleaned up, when code gets compiled and optimized. That's convenient, right up until it isn't.

I learned this in production, during an AWS migration cutover. New JVM instances took traffic before they had warmed up, and the cold start turned into 5xx errors. Nothing in our code warned us. The cost was real, but it lived in the runtime, not in anything we had written.

In Rust, that kind of cost shows up while you write the code, not after you ship it. It's slower to write. The compiler stops you constantly and asks: do you want to borrow this, copy it, or give it away? That gets annoying. But it means the performance is in your hands, not discovered later.

It pays off at scale too. When Anthropic moved its Messages API from Python to Rust, it used about 70% less CPU per request and cut median time to first token by about 20%. To me the point isn't the size of the numbers. It's that when each request's cost is visible, you can reason about it.

What changed for me

If I were starting a new project today, I'd choose Rust. I want a language where the cost is in plain sight from day one.

But most of the code I write lives in existing systems, and rewriting them isn't the answer. What I can change is how I read and write that code. I now ask a question I never used to ask: what is this line hiding?

Is this creating objects I don't need? Is this copy happening silently? Will this service be slow before it warms up?

Sometimes the answer is "it doesn't matter here," and that's fine. The difference is that now I'm the one making that call, not the language.

Rust didn't make me a faster programmer. It made the hidden cost visible, and once you see it, you can't unsee it.