Say I have the following dependency graph:
MyCrate
- A
- C
- D
- E
- F
- B
Let's say every crate takes 5 seconds to compile, except for B, which takes 30 seconds to compile, and MyCrate. Let's say I have a two-cores processors.
I'm pretty sure how long the dependencies take to compile will depend on which order the crates are compiled in:
- If A's dependencies are compiled before B, then the compilation sequence will be (C, D), (E, F), (G, H), (A, B), (B), (B), (B), (B), (B), (MyCrate) (where each tuple is a 5-seconds chunk), so a 50 seconds build.
- If B is started right away, then the compilation sequence will be (B, C), (B, D), (B, E), (B, F), (B, G), (B, H), (A), (MyCrate), so a 40 seconds build.
(the above assumes that an individual crate gets no benefit from multi-threaded compilation, which I understand is close to true)
So, in the above scenario, is there a way to make sure B's compilation is started first?
(For the real world use-case, druid
's build time on Linux is dominated by the gtk
dependency, which is both the longest to compile and the last to be started. I'm wondering if reordering things in Cargo.toml might accelerate the build. Though now that I mention it, I guess I could test it myself. Mhh...)