Live data from Hacker News

Why is my Rust build so slow?

fasterthanli.me

11–20 of 217 posts

Re: Why is my Rust build so slow?

#11

Rust's slow compiles are such a turn off for me. Like why does it take tens of seconds to recompile when I am just changing a single number in a file? Does it really need to waste so much of my time to change a single byte in the output binary?

I once had a similar project to OP that took 30 seconds to compile a one-line change (albeit on a 10-year-old CPU). I split it into about 7 crates, and got compiles down to 3 seconds. Since then I'm always vigilant about keeping crates nice and small. I think as long as you're keeping an eye on your crate sizes, compile times won't get away from you.

This is different from C++ where each individual source file can be compiled in parallel, so it's something I had to re-learn.

Re: Why is my Rust build so slow?

#12
I've always wondered why useful flags like `-Z timings` are not available on stable. I guess they're worried about the output changing in a future stable release, but I don't think anyone would expect the reports to look exactly the same and list exactly the same compilation phases, etc, for all eternity. I think that for diagnostic features, people would be just fine with a loose stability guarantee that allows the output to be improved in the future.

Re: Why is my Rust build so slow?

#13

Rust's slow compiles are such a turn off for me. Like why does it take tens of seconds to recompile when I am just changing a single number in a file? Does it really need to waste so much of my time to change a single byte in the output binary?

Are you using incremental compilation? Ive personally never had problems with incremental compiles. Sure, production builds are slow, but that's rarely a problem.

Re: Why is my Rust build so slow?

#14

Rust's slow compiles are such a turn off for me. Like why does it take tens of seconds to recompile when I am just changing a single number in a file? Does it really need to waste so much of my time to change a single byte in the output binary?

I once had a similar project to OP that took 30 seconds to compile a one-line change (albeit on a 10-year-old CPU). I split it into about 7 crates, and got compiles down to 3 seconds. Since then I'm always vigilant about keeping crates nice and small. I think as long as you're keeping an eye on your crate sizes, compile times won't get away from you. This is different from C++ where each individual source file can be…

What was your heuristic for deciding if a crate is too big or not?

Re: Why is my Rust build so slow?

#15

Earlier quoted context omitted.

Use bazel? Individual files won't be faster but it's been a wonder for whole project compilations

This could be interesting to look into. It looks like there already exists a project that can generate BUILD files for external crates. My 2 main gripes with Bazel was that it was a pain having to rewrite the build system for all of my dependencies and that it's claim of being reproducible is weak in the sense that there are not even warnings when you use resources from the base system (eg. compilers can include file…

Yep, agree on all fronts, the last point being especially painful when working on software you distribute to end users whose systems aren't in your control.

Re: Why is my Rust build so slow?

#16

Rust's slow compiles are such a turn off for me. Like why does it take tens of seconds to recompile when I am just changing a single number in a file? Does it really need to waste so much of my time to change a single byte in the output binary?

You are right. There is no technical reason it should be as slow as it is. It's just that not enough resource was spent to make it fast. I mean, if this were a higher priority, Rust issue #26600 would have been fixed years ago.

https://github.com/rust-lang/rust/issues/26600

Re: Why is my Rust build so slow?

#17

Rust's slow compiles are such a turn off for me. Like why does it take tens of seconds to recompile when I am just changing a single number in a file? Does it really need to waste so much of my time to change a single byte in the output binary?

Contrary to most, I actually like the long compile times. I also like programming in Rust without a linter. It really makes me think about what it is I'm doing. I do not have the luxury of typing something down, compiling it, and running it after every change to see: "does it work now?" To be fair, that's only in my personal projects. I understand this is a major issue in the "ship it quickly -- everything else be da…

No offense, but I want to hate this opinion, yet I kind of agree with it on some level. There was a time where I could write several pages of compilable code on paper, using the standard library and 3rd party dependencies, without looking at docs or anything. I could do that after a relatively short time after using a language.

Now, I can still do the same, but that's after spending years using a particular language or ecosystem.

I wouldn't want to go back to writing code on paper without docs, but it definitely made you think differently when it came to both writing code and learning. Kind of like how when you had a question about something before the internet, you had to stew with it until you could answer it yourself, or until you met someone who could answer your question, or you did your own research. Now, I can take out my phone and answer most questions within 20 seconds.

Re: Why is my Rust build so slow?

#18
The long compile times are actually one of Rust's problems I could live with.

Having to depend on so many third party libs is a much bigger issue for long term maintainability and security. Also the time choosing the libs is not neglectible. At work we currently developing a mid size project (CLI and HTTP API) with Go and the standard lib is simply amazing.

Re: Why is my Rust build so slow?

#19

Rust's slow compiles are such a turn off for me. Like why does it take tens of seconds to recompile when I am just changing a single number in a file? Does it really need to waste so much of my time to change a single byte in the output binary?

> Like why does it take tens of seconds to recompile when I am just changing a single number in a file?

Impossible to tell without knowing more. Steps to reproduce the issue would help. Just consider how TFA went through many different things to investigate.

> Does it really need to waste so much of my time to change a single byte in the output binary?

Does it actually only change a single byte in the binary? Changing a single value can cascade much further than that.

Re: Why is my Rust build so slow?

#20

Rust's slow compiles are such a turn off for me. Like why does it take tens of seconds to recompile when I am just changing a single number in a file? Does it really need to waste so much of my time to change a single byte in the output binary?

Use bazel? Individual files won't be faster but it's been a wonder for whole project compilations

Does anyone have an example of a Rust Bazel build project?

Or even better, a massive Rust monorepo orchestrated with Bazel build?

Post reply on HN