Add build profile. by ehuss · Pull Request #6577 · rust-lang/cargo (original) (raw)
I have some concerns about this, so I wanted to open this for discussion.
dev/release switching
With this feature, if a dev build is made, and then a release build is made, all of the build
artifacts are unnecessarily compiled again because they are in different directories. Some thoughts to work around this:
- Use a dedicated
build
directory. This would make it difficult/impossible to share common dependencies. - Combine
debug
andrelease
directories. This would make it easier to share artifacts. Of course this would probably cause madness for tools that make assumptions about Cargo's internal layout. I'm not really sure why they are separate directories.
Extra artifacts
I'm very worried about this causing shared dependencies to now be built multiple times.
Some options:
- Set the defaults of
build
to the same asdev
so that shared deps get reused opportunistically. This would not help forrelease
builds. - Reuse shared dependencies preferring
dev
orrelease
artifacts if available (and compatible). However, I think that would be very difficult to implement. The unit dependency builder might need to be a two-pass algorithm, which would complicate it quite a bit.
I've been doing some analysis on crates.io to try to understand the impact.
3187 of 21098 crates have at least one overlapping dependency. gist. crossgen has a whopping 161 crates in common worst case.
I did some tests "without" build profile and "with" build profile with either 12 or 2 concurrency. All times in seconds. These is just a rough idea. I ran each attempt multiple times, but this is particular to my hardware, and running on MacOS.
Package | j12 Without | j12 With | j2 Without | j2 With | Notes |
---|---|---|---|---|---|
rand | 44.3 | 40.6 (⨉0.92) | 43.0 | 43.7 (⨉1.01) | +0 crates |
cargo | 81.4 | 76.6 (⨉0.94) | 129.8 | 129.7 (⨉1.00) | +3 crates |
ripgrep | 27.2 | 28.1 (⨉1.03) | 58.6 | 62.3 (⨉1.06) | +6 crates |
gluon | 66.5 | 61.9 (⨉0.93) | 112.7 | 115.2 (⨉1.02) | +35 crates |
imag | 81.4 | 100.4 (⨉1.23) | 231.5 | 266.4 (⨉1.15) | +79 crates |
As you can see, sometimes it is a little faster, but usually it is slower (sometimes much slower).
Here's a few more pieces of data that seemed interesting (of 21098 crates):
- Crates that appear most often as host dep
- Crates that appear most often as direct build dep
- Crates that appear most often as proc-macro
Default settings
The current defaults may not be the best. Turning off debug improves speed and reduces disk space, but then you lose good backtraces. It's also questionable if it matters if debug-assertions or overflow-checks are off. Setting opt-level=1 had a noticeable increase in compile time on the few projects I tried, so I left it at 0.