-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
ComputeCriticalPath: Use topological sort to speed up function. #2443
ComputeCriticalPath: Use topological sort to speed up function. #2443
Conversation
Awesome! @peterbell10 can you have a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, just a couple small comments.
src/build.cc
Outdated
for (auto reverse_it = sorted_edges.end(); | ||
reverse_it != sorted_edges.begin();) { | ||
Edge* edge = *(--reverse_it); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT:
for (auto reverse_it = sorted_edges.end(); | |
reverse_it != sorted_edges.begin();) { | |
Edge* edge = *(--reverse_it); | |
for (auto reverse_it = sorted_edges.rbegin(); | |
reverse_it != sorted_edges.rend(); ++reverse_it) { | |
Edge* edge = *reverse_it; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I always forget about these. Thanks.
src/build.cc
Outdated
|
||
// First, reset all weights to 1. | ||
for (Edge* edge : sorted_edges) | ||
edge->set_critical_path_weight(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edge->set_critical_path_weight(1); | |
edge->set_critical_path_weight(EdgeWeightHeuristic(edge)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edge weight for phony edges is 0, so this is a meaningful change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point! Done.
Use a topological sort to get a sorted list of edges to perform the critical path weigth propagation as fast as possible. The previous version used a data flow algorithm that forced the values to be recomputed several times for far too many edges on complex build plans. For example, for a Fuchsia build plan with 93339 edges, this reduces the ComputeCriticalPath metric from 1.9s to 80ms! The unit-tests still pass, and manual testing shows that the order of commands does not change before and after this change for the example build plan above.
982848d
to
ef89584
Compare
Use a topological sort to get a sorted list of edges to perform the critical path weigth propagation as fast as possible.
The previous version used a data flow algorithm that forced the values to be recomputed several times for far too many edges on complex build plans.
For example, for a Fuchsia build plan with 93339 edges, this reduces the ComputeCriticalPath metric from 1.9s to 80ms!
The unit-tests still pass, and manual testing shows that the order of commands does not change before and after this change for the example build plan above.