Top
Best
New

Posted by Bogdanp 6/26/2025

Why is the Rust compiler so slow?(sharnoff.io)
303 points | 428 commentspage 2
edude03 6/27/2025|
First time someone I know in real life has made it to the HN front page (hey sharnoff, congrats) anyway -

I think this post (accidentally?) conflates two different sources of slowness:

1) Building in docker 2) The compiler being "slow"

They mention they could use bind mounts, yet wanting a clean build environment - personally, I think that may be misguided. Rust with incremental builds is actually pretty fast and the time you lose fighting dockers caching would likely be made up in build times - since you'd generally build and deploy way more often than you'd fight the cache (which, you'd delete the cache and build from scratch in that case anyway)

So - for developers who build rust containers, I highly recommend either using cache mounts or building outside the container and adding just the binary to the image.

2) The compiler being slow - having experienced ocaml, go and scala for comparisons the rust compiler is slower than go and ocaml, sure, but for non interactive (ie, REPL like) workflows, this tends not to matter in my experience - realistically, using incremental builds in dev mode takes seconds, then once the code is working, you push to CI at which point you can often accept the (worst case?) scenario that it takes 20 minutes to build your container since you're free to go do other things.

So while I appreciate the deep research and great explanations, I don't think the rust compiler is actually slow, just slower than what people might be use to coming from typescript or go for example.

ozgrakkurt 6/26/2025||
Rust compiler is very very fast but language has too many features.

The slowness is because everyone has to write code with generics and macros in Java Enterprise style in order to show they are smart with rust.

This is really sad to see but most libraries abuse codegen features really hard.

You have to write a lot of things manually if you want fast compilation in rust.

Compilation speed of code just doesn’t seem to be a priority in general with the community.

aquariusDue 6/27/2025||
Yeah, for application code in my experience the more I stick to the dumb way to do it the less I fight the borrow checker along with fewer trait issues.

Refactoring seems to take about the same time too so no loss on that front. After all is said and done I'm just left with various logic bugs to fix which is par for the course (at least for me) and a sense of wondering if I actually did everything properly.

I suppose maybe two years from now we'll have people that suggest avoiding generics and tempering macro usage. These days most people have heard the advice about not stressing over cloning and unwraping (though expect is much better imo) on the first pass more or less.

Something something shiny tool syndrome?

skeezyboy 6/27/2025||
>Compilation speed of code just doesn’t seem to be a priority in general with the community.

they have only one priority, memory safety (from a certain class of memory bugs)

duped 6/26/2025||
A lot of people are replying to the title instead of the article.

> To get your Rust program in a container, the typical approach you might find would be something like:

If you have `cargo build --target x86_64-unknown-linux-musl` in your build process you do not need to do this anywhere in your Dockerfile. You should compile and copy into /sbin or something.

If you really want to build in a docker image I would suggest using `cargo --target-dir=/target ...` and then run with `docker run --mount type-bind,...` and then copy out of the bind mount into /bin or wherever.

remram 6/27/2025||
The author dismissed that option saying "I value that docker build can have a clean environment every time", so this is self-inflicted.
edude03 6/27/2025||
Many docker users develop on arm64-darwin and deploy to x86_64 (g)libc, so I don't think that'll work generally.
duped 6/27/2025||
Those users are wrong :shrug:
smcleod 6/26/2025||
I've got to say when I come across an open source project and realise it's in rust I flinch a bit know how incredibly slow the build process is. It's certainly been one of the deterrents to learning it.
feelamee 6/27/2025||
> Vim hangs when you open it

you can enable word wrapping as a workaround ( `:set wrap`). Lifehack: it can be hard to navigate in such file with just `h, j, k, l`, but you can use `gh, gj, etc`. With `g` vim will work with visual lines, while without it with just lines splitted with LF/CRLF

mmh0000 6/27/2025|
With a little bit of vimrc magic you can make it transparent:

  "Make k/j up/down work more naturally by going to the next displayed line vs
  "going to the next logical line (for when word-wrapping is on):
  noremap k gk
  noremap j gj
  noremap <up> gk
  noremap <down> gj
  "Same as above, but for arrow keys in insert mode:
  inoremap <up> <Esc>gka
  inoremap <down> <Esc>gja
s_ting765 6/27/2025||
OP could have skipped all this by doing the compilation with cache on the host system and copying the compiled statically linked binary back to the docker image build.
amelius 6/27/2025||
Meanwhile, other languages have a JIT compiler which compiles code as it runs. This would be great for development even if it turns out to be slower overall.
akkad33 6/27/2025|
Actually JITs can be faster than AOT compilation because they can be optimized for the current architecture they are running in. There were claims Julia, a JIT language can beat C in some benchmarks
amelius 6/27/2025||
In fact, JITs can be faster because they can specialize code, i.e. make optimizations based on live data.
ecshafer 6/26/2025||
The Rust compiler is slow. But if you want more features from your compiler you need to have a slower compiler, there isn't a way around that. However this blog post doesn't really seem to be around that and more an annoyance in how they deploy binaries.
aappleby 6/26/2025||
you had a functional and minimal deployment process (compile copy restart) and now you have...
canyp 6/27/2025|
...Kubernetes.

Damn, this makes such a great ad.

cratermoon 6/26/2025|
Some code that can make Rust compilation pathologically slow is complex const expressions. Because the compiler can evaluate a subset of expressions at compile time[1], a complex expression can take an unbounded amount of time to evaluate. The long-running-const-eval will by default abort the compilation if the evaluation takes too long.

1 https://doc.rust-lang.org/reference/const_eval.html

More comments...