-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
idea for further improvement of build scheduling #5125
Comments
Certainly! Our goal is to always keep all the cpus busy, so anything that optimizes work to get opened up I think looks great as an ordering. |
I am totally unfamiliar with the dependency scheduling in cargo, but is a "static" order the best way? Shouldn't we re-compute which crate to build every time we are done with one and a cpu is free? |
@fabricedesre yeah that's basically what happens today. The question here is how to prioritize work when there's multiple candidates to be scheduled, the code for the current iteration is at https://github.com/rust-lang/cargo/blob/master/src/cargo/util/dependency_queue.rs |
So #7390 changed the build order, but not in a way that will affect the OP. #7390 fixes the case
Where finishing |
To extend my comment from #7396: The problem that cargo has to solve is known as the multiprocessor DAG scheduling problem, which is NP complete so we can only apply approximations. The good news is that the problem is well-known in the literature and you can find a wealth of papers about the topic. E.g. this one is fairly recent, or this one. I suppose it would be a good idea to somehow account for the projected build time of a certain crate. Those are dependent from the feature flags as well as the platform, winapi is quite trivial to build on linux while it takes longer on windows. Issue #7396 is exploring this idea a bit. A project to find a better scheduling algorithm is a great opportunity for experimentation. One could e.g. parse crater logs to find out how long each crate takes to build and then use that information to build a "virtual" crater where the results of different scheduling algorithms are compared using different CPU numbers etc. Then we'd find the scheduling algorithm that fits the cargo use case best. The final implementation of the scheduling algorithm could be even put into its own crate, for use in the ecosystem, similar to polonius. |
#11032 made us take priority into account in more cases. As part of the experiments for that, some other priority tweaks were looked into. See the zulip thread |
Reading more on #11032, it sounds like this is fully implemented From:
If there is something I'm missing, let us know! |
I'm trying to understand #5100
Lets assume we have a dependency tree like this
depth annotation would be something like this?
as far as I understand, build order will be like this:
It might be useful to not only take depth but also the number of child nodes (in braces) into account, like this:
If we have several crates of equal depth, we could look at the number of child nodes and prioritize the crate with the most (total) child nodes (assuming that crates with a lot of dependencies are bigger that those with only few dependencies).
New build order:
Does this sound resonable?
edit: aid for debugging
RUST_LOG=cargo::core::compiler::job_queue cargo check
The text was updated successfully, but these errors were encountered: