Improve performance of package ordering/tagging after version solving #2906
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.
This PR greatly improves the performance of package ordering/tagging which occurs during package solving, after the version solving itself has been completed. In certain cases, the current algorithm has exponential time complexity and starts to really break down when the package dependency graph is dense. I've added a test case for one such scenario, where the dependencies form a transitive tournament. On
master
this test takes several minutes to run with my hardware, but only takes around 100ms with this patch.I've noticed on personal projects that it's very easy to run into this issue when using
aws_cdk
.At the core of the new algorithm is a depth-first search which is used to compute a topological sort of the packages. Using the topological ordering, the longest path / depth of each package can be computed.
Along the way I noticed that the current algorithm does not correctly check for dependency cycles and in certain cases will trigger a
RecursionError
. I've added a test case for this scenario as well.Pull Request Check List
This may be related to #2642 and #2149, which both mention using
aws_cdk
.