Repository navigation
ComputeCriticalPath: Use topological sort to speed up function. - #2443
Merged
jhasse merged 1 commit intoMay 11, 2024
Merged
Conversation
Contributor
Author
Collaborator
|
Awesome! @peterbell10 can you have a look? |
peterbell10
reviewed
May 9, 2024
peterbell10
left a comment
Contributor
There was a problem hiding this comment.
Makes sense to me, just a couple small comments.
Comment on lines
+533
to
+535
| for (auto reverse_it = sorted_edges.end(); | ||
| reverse_it != sorted_edges.begin();) { | ||
| Edge* edge = *(--reverse_it); |
Contributor
There was a problem hiding this comment.
NIT:
Suggested change
| 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; |
Contributor
Author
There was a problem hiding this comment.
Oh, I always forget about these. Thanks.
|
|
||
| // First, reset all weights to 1. | ||
| for (Edge* edge : sorted_edges) | ||
| edge->set_critical_path_weight(1); |
Contributor
There was a problem hiding this comment.
Suggested change
| edge->set_critical_path_weight(1); | |
| edge->set_critical_path_weight(EdgeWeightHeuristic(edge)); |
Contributor
There was a problem hiding this comment.
Edge weight for phony edges is 0, so this is a meaningful change.
Contributor
Author
There was a problem hiding this comment.
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.
digit-google
force-pushed
the
critical-path-with-topo-sort
branch
from
May 9, 2024 08:26
982848d to
ef89584
Compare
peterbell10
approved these changes
May 9, 2024
jtmorrisbytes
pushed a commit
to jtmorrisbytes/ninja-rs
that referenced
this pull request
May 4, 2026
…ith-topo-sort ComputeCriticalPath: Use topological sort to speed up function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.