News for hackers. Stuff that matters.
Re:Why is my Rust build so slow? by izacus on Friday December 31, 2021 @03:55AM (#29746168)
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).
Re:Why is my Rust build so slow? by estebank on Friday December 31, 2021 @03:58AM (#29746180)
If you encounter incomprehensible error messages, I would encourage you to file a ticket at http://github.com/rust-lang/rust/issues. We consider them bugs and are diligent about dealing with them.
Re:Why is my Rust build so slow? by ogoffart on Friday December 31, 2021 @10:09AM (#29748673)
The worst error message was basically no error message. After I made some big refactoring to my project, cargo would just exit with:

   error: could not compile `the_project`.
And nothing else. No hint of what the problem is.

It then took me a long time to try to comment out code here and there to find out what was causing the error.

When I finally found out the problem, I took the time to fill a bug report. I don't know if anyone looked at it. https://github.com/rust-lang/rust/issues/73026

Re:Why is my Rust build so slow? by estebank on Friday December 31, 2021 @10:18AM (#29748764)
Thank you for the great report. It indeed seems to have fallen through the cracks, with no one touching it (it's missing the T-compiler tag, which means I didn't triage it) since it was first cathegorized.

I wouldn't call that lack of output representative of the experience of using rustc though, if I'm allowed to let my pride on my work flare up a bit.

Re:Why is my Rust build so slow? by ogoffart on Friday December 31, 2021 @10:41AM (#29749001)
Sorry, I did not mean to say that this was representative of the overall experience. On the contrary, I'm usually quite satisfied with the compiler messages. Thanks for your work!
Re:Why is my Rust build so slow? by estebank on Friday December 31, 2021 @10:47AM (#29749075)
Thank you! The "bad" thing about having high standards is that when it isn't met it is quite jarring, more so than if it were homogeneously bad or meh, and that ends up bring more frustrating.
Re:Why is my Rust build so slow? by Uther on Friday December 31, 2021 @04:22AM (#29746298)
While compilation time is a well known Rust pain point, Rust error messages are really one of the best part of the language.

Complicated error messages are clearly no a common occurrence unless you rely heavily on meta-programming tricks, and that is not common in Rust, unlike C++.

Re:Why is my Rust build so slow? by estebank on Friday December 31, 2021 @04:30AM (#29746336)
And the intention is to improve those too. It's hard, and I would prefer crate writers show more restrain than they do, but we have to meet users where they are.
Re:Why is my Rust build so slow? by Ygg2 on Friday December 31, 2021 @04:03AM (#29746201)
What the hell are you on about?

Saying in it inherited them, just proves you probably didn't use either.

While compilation times are longer than say Go, they definitely never felt too long, compared to say Java.

But your comment around errors takes the cake. Like maybe, if you use some combination of macros expansion and traits it could get confused.

But Rust errors are on par with Elm. They show the line, they show what went wrong and how to fix. This is a far cry from C++, where using even a bit of templates, results in unintelligible mess.

Re:Why is my Rust build so slow? by brabel on Friday December 31, 2021 @04:31AM (#29746343)
> 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, it's mentioned in the beginning) was taking over a minute even on hot builds... To get a build to take this long in Java you would need to have several million LoC! Even if you don't use something like Gradle to cache compilation units and just compile everything from scratch with javac.

Re:Why is my Rust build so slow? by fasterthanlime on Friday December 31, 2021 @08:06AM (#29747635)
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.
Re:Why is my Rust build so slow? by yawaramin on Friday December 31, 2021 @11:59AM (#29749886)
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? by estebank on Friday December 31, 2021 @01:01PM (#29750617)
It's a tradeoff: if you make the file the language's compilation unit, then you can't have "circular imports" to allow end users divide their code in an ergonomic manner with fewer "arbitrary" restrictions. We can argue all year on whether Rust settled on the right side of that trade-off.
Re:Why is my Rust build so slow? by yawaramin on Friday December 31, 2021 @05:59PM (#29753405)
I'm just surprised that no one has (to my knowledge, anyway) tried this even experimentally. Wouldn't the potential build speed improvement be worth at least trying out the one-file-per-crate strategy?
Re:Why is my Rust build so slow? by Ygg2 on Friday December 31, 2021 @05:22AM (#29746588)
And I've worked on large Java projects.

Things that have like 420+ dependencies (spring boot + some other requirements). I timed the maven clean compile. And it takes around 2min.

Re:Why is my Rust build so slow? by brabel on Friday December 31, 2021 @10:26AM (#29748835)
Maven is very slow. Gradle and Bazel avoid doing wasteful things like Maven does so generally are a lot faster... if you want to know the speed of compiling Java you should just run `javac`, assuming Maven speed is Java compilation speed is far from correct even if a lot of projects still use Maven to build Java projects.
Re:Why is my Rust build so slow? by lenkite on Saturday January 01, 2022 @07:05PM (#29764245)
Use Maven Daemon. (https://github.com/apache/maven-mvnd) . With Maven Daemon, traditional maven builds get a spectacular boost factor that put them ahead of Gradle. (Haven't tried Bazel though)
Re:Why is my Rust build so slow? by dmitriid on Friday December 31, 2021 @04:41AM (#29746388)
> 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.

Re:Why is my Rust build so slow? by emn13 on Friday December 31, 2021 @11:59AM (#29749877)
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? by yawaramin on Friday December 31, 2021 @12:03PM (#29749930)
Not surprising, considering the chief architect of C# is the guy famous for making Turbo Pascal.
Re:Why is my Rust build so slow? by tialaramex on Friday December 31, 2021 @08:16AM (#29747695)
Rust's errors are definitely the best of any language I've used. That's one reason it's nice to write Rust after a day fighting with SQL Server for example which seems to still think in 2021 that "Syntax error" is a reasonable diagnostic message.

As to "How to fix it" however if you have lifetime confusion the error reported by the borrow checker probably isn't going to suggest refactoring your code with a design that makes sense even though that's likely the correct solution. It would be cute if the Rust compiler said "I think you want a Boxed collection of strings here to use the algorithm you're attempting, change how this is represented in all the related structs too, here's how:" but that's unrealistic and, more importantly, no other language is doing a better job here.

While Rust makes the errors themselves look easy, the right suggestion is context sensitive anyway. In my AoC solutions, unwrap() was the correct answer anywhere the problem is "I have an Option or a Result and I wish that I didn't". Because it's AoC if I'm wrong to be so cavalier I will eat a panic immediately, and I don't plan to maintain this stuff. In a real project I probably want to explicitly handle None and Error in some places, and pass on Errors in other places, even when I don't I should write an expect() in case I'm maintaining this years from now.

More likely in lifetime confusion scenarios the equivalent C++ compiles but just has mysterious crashes or bugs and the equivalent Java has runtime Null reference errors, Concurrency errors, a truly enormous memory leak, data races, other mysterious mutation bugs, or all of the above. I'll take a compile time error from the borrow checker thanks.

Re:Why is my Rust build so slow? by estebank on Friday December 31, 2021 @09:18AM (#29748246)
> It would be cute if the Rust compiler said "I think you want a Boxed collection of strings here to use the algorithm you're attempting, change how this is represented in all the related structs too, here's how:" but that's unrealistic

I think we could provide such messages in some cases. :)

For example, if you have an impl Trait return type and have multiple returned values of different types, we suggest using Box<dyn Trait> when valid. It's just a lot of work to get those in place. You're effectively implementing a language that does those things automatically, plus all the work to print out the actual diagnostic.

Re:Why is my Rust build so slow? by ModernMech on Friday December 31, 2021 @09:21AM (#29748269)
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.
Re:Why is my Rust build so slow? by izacus on Friday December 31, 2021 @11:59AM (#29749884)
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? by UtherII on Friday December 31, 2021 @04:47PM (#29752867)
Have you really used Rust on big codebases? One of the big advantage of Rust is especially that it fails far earlier than C++. Borrow checker error are local error that prevent bad behavior to propagate and cause problem on unexpected part.
Re:Why is my Rust build so slow? by space_rock on Friday December 31, 2021 @05:07AM (#29746499)
Someone has never used Rust
Re:Why is my Rust build so slow? by mlindner on Wednesday January 05, 2022 @07:26AM (#29808111)
Rust has some of the best compiler error messages out there so not sure what you're talking about there. And C++'s compiler error message issue stopped being an issue since like GCC 4.