6 ms·
I like so much about Rust. But I hear compiling is too slow. Is it a serious problem in practice?
by 90s_dev 1y ago
I like so much about Rust.
But I hear compiling is too slow.
Is it a serious problem in practice?
- zozbot234 1y agoPeople who say "Rust compiling is so slow" have never experienced what building large projects was like in the mid-1990s or so. It's totally fine. Besides, there's also https://xkcd.com/303/ https://xkcd.com/303/
- kelnos 1y agoNot really relevant. The benchmark is how other language toolchains perform today, not what they failed to do 30 years ago. I don't think we'd find it acceptable to go back to mid-'90s build times in other languages, so why should we be ok with it with something like Rust?
- creata 1y agoOr maybe they have experienced what it was like and they don't want to go back.
- mynameisash 1y agoIt depends on where you're coming from. For me, Rust has replaced a lot of Python code and a lot of C# code, so yes, the Rust compilation is slow by comparison. However, it really hasn't adversely affected (AFAICT) my/our iteration speed on projects, and there are aspects of Rust that have significantly sped things up (eg, compilation failures help detect bugs before they make it into code that we're testing/running). Is it a serious problem? I'd say 'no', but YMMV.
- Seattle3503 1y agoAbsolutely, the compile times are the biggest drawback IMO. Everywhere I've been that built large systems in Rust eventually ends up spending a good amount of dev time trying to get CI/CD pipeline times to something sane. Besides developer productivity it can be an issue when you need a critical fix to go out quickly and your pipelines take 60+ minutes.
- deleted 1y ago[deleted]
- lilyball 1y agoDon't use a single monolithic crate. Break your project up into multiple crates. Not only does this help with compile time (the individual crate compiles can be parallelized), it also tends to help with API design as well.
- mixmastamyk 1y agoIt compiles different files separately, right? With some exceptions for core data structures, it seems that if you only modified a few files in a large project the total compilation time would be quick no matter how slow the compiler was.
- conradludgate 1y agoSorta. The "compilation unit" is a single crate, but rustc is now also parallel, and LLVM can also be configured to run in parallel IIRC. Rust compile times have been improving over time as the compiler gets incrementally rewritten and optimised.
- Seattle3503 1y agoEvery project I've worked on used a workspace with many crates. Generally that only gets you so far on large projects.
- nicoburns 1y agoIf you have the money to throw at it, you can get a long way optimising CI pipelines just by throwing faster hardware at it. The sort of server you could rent for ~$150/month might easily be ~5x faster than your typical Github Actions hosted runner.
- Seattle3503 1y agoYes, this is often the best "low-hanging fruit" option, but it can get expensive. It depends how you value your developer time.
- cmrdporcupine 1y agoI worked in the chromium C++ source tree for years and compiling there was orders of magnitude slower than any Rust source tree I've worked in so far. Granted, there aren't any Rust projects that large yet, but I feel like compilation speeds are something that can be worked around with tooling (distributed build farms, etc.). C++'s lack of safety and a proclivity for "use after free" errors is harder to fix.
- gpderetta 1y agoAre there rust projects that are within orders of magnitude of Chromium?
- kelnos 1y agoCompilation is indeed slow, and I do find it frustrating sometimes, but all the other benefits Rust brings more than make up for it in my book.
- juliangmp 1y agoI can't speak for a bigger rust project, but my experience with C++ (mostly with cmake) is so awful that I don't think it can get any worse. Like with any bigger C++ project there's like 3 build tools, two different packaging systems and likely one or even multiple code generators.
- thawawaycold 1y agothat does not answer at all OP's question.
- juliangmp 1y ago"It can't get any worse than C++" That's my response. So just use rust. In the long run you'll save time as well.
- conradludgate 1y agoIt is slow, and yes it is a problem, but given that typical Rust code generally needs fewer full compiles to get working tests (with more time spent active in the editor, with an incremental compiler like Rust Analyzer) it usually balances out. Cargo also has good caching out of the box. While cargo is not the best build system, it's an easy to use good system, so you generally get good compile times for development when you edit just one file. This is along made heavy use of with docker workflows like cargo-chef.
- throwaway76455 1y agoCompile times are the reason why I'm sticking with C++, especially with the recent progress on modules. I want people with weaker computers to be able to build and contribute to the software I write, and Rust is not the language for that.
- ttfkam 1y agoC++ compiles quickly? News to me.
- ttfkam 1y agoYes, Rust compiling is slow. Then again, I wouldn't say that C++ is exactly speedy in that area either. Nor Java. None of those are even in the same zip code to Go's compile speed. So if you're cool with C++ or Java compile times, Rust will generally be fine. If you're coming from Go, Rust compiles will fell positively glacial.