blog.rust-lang.org
Workarounds For Improving...
While it is great to see some developers being happy with the state we have today, it is clear that many people are not so lucky, and Rust's build performance limits their productivity. Around 45% respondents who answered that they are no longer using Rust said that at least one of the reasons why they stopped were long compile times. … ## Important workflows ... Waiting too long for an incremental rebuild after making a small source code change was by far the most common complaint in the open answers that we received, and it was also the most common problem that respondents said they struggle with. Based on our respondents' answers, this comes down to three main bottlenecks: … **The linking phase is too slow.** This was a very common complaint, and it is indeed a real issue, because unlike the rest of the compilation process, linking is always performed "from scratch". The Rust compiler usually delegates linking to an external/system linker, so its performance is not completely within our hands. However, we are attempting to switch to faster linkers by default. … - **Incremental rebuild of a single crate is too slow.** The performance of this workflow depends on the cleverness of the incremental engine of the Rust compiler. While it is already very sophisticated, there are some parts of the compilation process that are not incremental yet or that are not cached in an optimal way. For example, expansion of derive proc macros is not currently cached, although work is underway to change that. ... To gauge how long is the typical rebuild latency, we asked our respondents to pick a single Rust project that they work on and which causes them to struggle with build times the most, and tell us how long they have to wait for it to be rebuilt after making a code change. [PNG] [SVG] Even though many developers do not actually experience this latency after each code change, as they consume results of type checking or inline annotations in their code editor, the fact that 55% of respondents have to wait more than ten seconds for a rebuild is far from ideal. … ### Clean and CI builds Around 20% of participants responded that clean builds are a significant blocker for them. In order to improve their performance, you can try a recently introduced experimental Cargo and compiler option called `hint-mostly-unused`, which can in certain situations help improve the performance of clean builds, particularly if your dependencies contain a lot of code that might not actually be used by your crate(s). One area where clean builds might happen often is Continuous Integration (CI). 1495 respondents said that they use CI to build Rust code, and around 25% of them consider its performance to be a big blocker for them. However, almost 36% of respondents who consider CI build performance to be a big issue said that they do not use any caching in CI, which we found surprising. … ## Understanding why builds are slow When Rust developers experience slow builds, it can be challenging to identify where exactly is the compilation process spending time, and what could be the bottleneck. It seems that only very few Rust developers leverage tools for profiling their builds:
Related Pain Points5件
Slow linking phase in compilation
7The linking phase is performed from scratch every time and is a major bottleneck in the build process. Since Rust delegates linking to external system linkers, performance improvements are limited, though the Rust team is attempting to switch to faster linkers by default.
Inefficient incremental compilation caching
7The Rust compiler's incremental engine has gaps where certain compilation parts are not incremental or not cached optimally. For example, expansion of derive proc macros is not currently cached, causing unnecessary recompilation.
Development velocity slowdowns from inner development loop friction
6Despite improvements in tooling and culture, many teams experience bottlenecks in everyday development work, particularly in the inner development loop where code changes and testing cycles introduce slowdowns.
Slow Docker build times in CI/CD pipelines
6Docker builds are slow on CI/CD pipelines, delaying deployment. Requires manual optimization (reordering Dockerfile, enabling BuildKit) that isn't default behavior.
Difficulty identifying build performance bottlenecks
5When developers experience slow Rust builds, it is challenging to identify where the compilation process is spending time and what the bottleneck is. Very few Rust developers leverage build profiling tools to diagnose issues.