Live data from Hacker News

Why is my Rust build so slow?

fasterthanli.me

161–170 of 217 posts

Re: Why is my Rust build so slow?

#161
post #154

Earlier quoted context omitted.

The third axis in compiler development is safety. The compiler writer’s dilemma can be framed as: fast execution, safe execution, fast compilation — choose 2.

ADA. This is a false(ish) dilema. The problem of Rust is that is made with a C++ mindset. Is VERY hard to make compiler fast if it follow what C/C++ do (Go is the only evidence against!). Is a death by thousands cut. The syntax is the FIRST and big one. How you chose it will impact all the pipeline. Then the rest...

Ada isn't entirely safe. It does avoid C-string issues using length-based strings, bounds-checking array access and other features like access types instead of pointers, but it is still possible to hold onto an access to dynamically allocated memory after deletion (though you can somewhat mitigate this with smart pointers).

Re: Why is my Rust build so slow?

#162
post #62

Earlier quoted context omitted.

> they definitely never felt too long, compared to say Java. Woah... now I am the one who have to ask: what the hell are you on about?? I work on Rust and Java projects, if you exclude running tests, Java compiles very very fast compared to pretty much any language... Rust is a lot slower to compile even on the much smaller projects I've worked on... in this post, a very small project (I think it's like 16,000 LoC, i…

> Java compiles very very fast compared to pretty much any language In my experience C# compiles faster, but I still agree with you on all points.

Build times have regressed considerably the past few releases (at least for me). Not that I'm complaining about the tradeoffs, the new features are generally worth it. Whats most annoying is that it's often hard to tell which features are expensive until you've already wasted a bunch of time introducing em.

But I've got to say I'm super jealous of the level of introspection the rust compiler allows here. I'd definitely be willing to change a few C# coding patterns in code bases I maintain to benefit build times, but as is, that's a really painful trial and error process. And sometimes you get lucky finding the root cause, but if you don't... well, it's not a great experience.

Re: Why is my Rust build so slow?

#163
post #46

Earlier quoted context omitted.

Rust seems to have inherited two favorite C++ development process features: long compilation times and incomprehensible error messages that aren't really related to the actual issue (e.g. just how C++ barfed out a bunch of template errors, borrow checker really loves to barf out very obscure error messages when there's an issue with lifetimes).

I teach C++ and Rust to college students, and their number one praise of Rust over C++ is how much more helpful the error messages are. It’s really night and day, so I can’t even fathom how you would equate the two.

It's easy to fathom once you go beyond the school examples and start working on bigger codebases. The error messages are verbose and simple until you hit cases where borrow checker complains about an error in a completely different part of the codebase than where the actual issue here is. This is where it behaves similar to C++ (and, honestly, some other languages) and there all the verbosity in the world doesn't help.

Re: Why is my Rust build so slow?

#164
post #62

Earlier quoted context omitted.

> they definitely never felt too long, compared to say Java. Woah... now I am the one who have to ask: what the hell are you on about?? I work on Rust and Java projects, if you exclude running tests, Java compiles very very fast compared to pretty much any language... Rust is a lot slower to compile even on the much smaller projects I've worked on... in this post, a very small project (I think it's like 16,000 LoC, i…

Seems like you really need to finish reading the article: hot builds take 3s by the time I find the regression that caused pathological compile times.

You mean, by the time you split up the project into a bunch of tiny crates and mention:

> I don't love how the dependency graph looks

After adding this complexity to the project, yes, some of the crates are building in ~3s, if they are the only ones that needed to be rebuilt.

Meanwhile, in a Java project there is none of this artificial crate splitting. Sure, Java projects have other nonsense, but they don't force you to split up projects into tiny pieces to get decent compile times.

Re: Why is my Rust build so slow?

#165
post #62

Earlier quoted context omitted.

> they definitely never felt too long, compared to say Java. Woah... now I am the one who have to ask: what the hell are you on about?? I work on Rust and Java projects, if you exclude running tests, Java compiles very very fast compared to pretty much any language... Rust is a lot slower to compile even on the much smaller projects I've worked on... in this post, a very small project (I think it's like 16,000 LoC, i…

> Java compiles very very fast compared to pretty much any language In my experience C# compiles faster, but I still agree with you on all points.

Not surprising, considering the chief architect of C# is the guy famous for making Turbo Pascal.

Re: Why is my Rust build so slow?

#166
post #65

Earlier quoted context omitted.

That's a pretty bad incentive though and you end up with very large dependency trees similar to JS. And we know how that went. OTOH there might be a benefit too as more code becomes re-usable in independent crates.

> That's a pretty bad incentive though and you end up with very large dependency trees similar to JS. And we know how that went. That's... not the same thing at all. Rust lets you have multiple crate in a single workspace, which allows parallelising the build (because crates are the concurrency unit of building rust). That's got nothing whatsoever to do with pulling random crates, which is a separate issue.

Why doesn't Rust default to one crate per source file then? Wouldn't that make the build massively parallelized :-)

Re: Why is my Rust build so slow?

#167

Earlier quoted context omitted.

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

Going by feel, same as when I have a giant function I decide to split up. IIRC the crates ended up between 1k-10k LOC

In OP the biggest crate after the split-up is 1,513 loc, with most of them a few hundred loc.

Re: Why is my Rust build so slow?

#168
post #139

Earlier quoted context omitted.

Including me! There’s a lot of daylight between “an old dual core laptop” and a last gen thread ripper. For example, I’m running on a quad core i7 from 2015.

My old dual core laptop from 2009 works just fine with Visual Studio 2022, even though I wasn't the OP. And long compile times kill the battery on the go, and cargo check hardly helps when writing GUI code.

I don’t think I follow the point you’re trying make. Are you trying to say Rust compile times are a problem for you on your 13 year old laptop in the context of writing GUI code on battery? If so I think that’s such a specific scenario that it’s hard to draw any generally applicable conclusions.

Re: Why is my Rust build so slow?

#169
post #75

This much complexity and the tribal knowledge required to bypass it, so early in the the life of a programming language, is a really bad sign. It means the complexity of the problem space is not solved by the language, and the responsibility of solving it is being passed on to the users. You might react to this by saying that slow build times are not a big deal. That's a mistake -- iteration is key to productivity an…

This is more of a step-by-step deep-dive into the ways to profile, diagnose and work through the timing and performance problems. Anyone who doesn't know about many of these tools will probably find them useful (or at least useful to know that they exist) in the future. Besides, for iteration people are probably in debug, not release mode, which the article mentions is initially 19s vs 2m+. As far as I can see the ma…

> This is more of a step-by-step deep-dive into the ways to profile, diagnose and work through the timing and performance problems.

I'd argue that when it comes to doing work, I only want to deep-dive into my code. Not third party libraries that "vow" to have been tested + performant, let alone the language/build tools themselves.

Re: Why is my Rust build so slow?

#170

Earlier quoted context omitted.

> That's a pretty bad incentive though and you end up with very large dependency trees similar to JS. And we know how that went. That's... not the same thing at all. Rust lets you have multiple crate in a single workspace, which allows parallelising the build (because crates are the concurrency unit of building rust). That's got nothing whatsoever to do with pulling random crates, which is a separate issue.

Why doesn't Rust default to one crate per source file then? Wouldn't that make the build massively parallelized :-)

Because you can have circular dependencies within a compilation unit, but not between units.
Post reply on HN