Top
Best
New

Posted by Bogdanp 6/26/2025

Why is the Rust compiler so slow?(sharnoff.io)
303 points | 428 commentspage 3
TZubiri 6/27/2025|
>Every time I wanted to make a change, I would:

>Build a new statically linked binary (with --target=x86_64-unknown-linux-musl) >Copy it to my server >Restart the website

Isn't it a basic C compiler feature that you can compile a file as an Object, and then link the objects into a single executable? Then you only recompile the file you changed.

Not sure what I'm missing.

pornel 6/27/2025|
That's how Rust works already.

The problem has been created by Docker which destroys all of the state. If this was C, you'd also end up losing all of the object files and rebuilding them every time.

TZubiri 6/27/2025||
Nope, reread the article, docker wasn't part of the problem it's part of the 'solution' according to OP.
saghm 6/29/2025||
My take on Rust build times is that the larger issue isn't the speed of compilation itself, but that it's actually pretty hard to avoid compiling a lot of unneeded code from dependencies. To be clear, this is a distinct concern from having too many dependencies (which is it's own issue, but I'd argue that it's a social one that doesn't need to be solved in order to significantly reduce build times, which can be done with a technical solution).

I wrote up a lot of my ideas in a blog post mostly to avoid having to repeat my thoughts on this every time it comes up: https://saghm.com/cargo-features-rust-compile-times/

kelnos 6/26/2025||
> This is... not ideal.

What? That's absolutely ideal! It's incredibly simple. I wish deployment processes were always that simple! Docker is not going to make your deployment process simpler than that.

I did enjoy the deep dive into figuring out what was taking a long time when compiling.

quectophoton 6/26/2025|
One thing I like about Alpine Linux is how easy and dumbproof it is to make packages. It's not some wild beast like trying to create `.deb` files.

If anyone out there is already fully committed to using only Alpine Linux, I'd recommend trying creating native packages at least once.

eddd-ddde 6/27/2025||
I'm not familiar with .deb packages, but one thing I love about Arch Linux is PKGBUILD and makepkg. It is ridiculously easy to make a package.
tmtvl 6/26/2025||
Just set up a build server and have your docker containers fetch prebuilt binaries from that?
OtomotO 6/26/2025||
It's not. It's just doing way more work than many other compilers, due to a sane type system.

Personally I don't care anymore, since I do hotpatching:

https://lib.rs/crates/subsecond

Zig is faster, but then again, Zig isn't memory save, so personally I don't care. It's an impressive language, I love the syntax, the simplicity. But I don't trust myself to keep all the memory relevant invariants in my head anymore as I used to do many years ago. So Zig isn't for me. Simply not the target audience.

mellosouls 6/27/2025||
Related from a couple of weeks ago:

https://news.ycombinator.com/item?id=44234080

(Rust compiler performance; 287 points, 261 comments)

ic_fly2 6/26/2025||
This is such a weird cannon on sparrows approach.

The local builds are fast, why would you rebuild docker for small changes?

Also why is a personal page so much rust and so many dependencies. For a larger project with more complex stuff you’d have a test suite that takes time too. Run both in parallel in your CI and call it a day.

gz09 6/26/2025||
Unfortunately, removing debug symbols in most cases isn't a good/useful option
magackame 6/26/2025|
What "most" cases are you thinking of? Also don't forget that a binary that in release weights 10 MB, when compiled with debug symbols can weight 300 MB, which is way less practical to distribute.
juped 6/26/2025||
I don't think rustc is that slow. It's usually cargo/the dozens of crates that make it take a long time, even if you've set up a cache and rustc is doing nothing but hitting the cache.
More comments...