Skip to content
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

Improve performance of package ordering/tagging after version solving #2906

Merged
merged 2 commits into from
Sep 15, 2020

Conversation

zweger
Copy link
Contributor

@zweger zweger commented Sep 11, 2020

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.

  • Added tests for changed code.
  • Updated documentation for changed code.

@abn
Copy link
Member

abn commented Sep 12, 2020

@sdispater this might need your review.

@abn abn added area/solver Related to the dependency resolver kind/enhancement Not a bug or feature, but improves usability or performance labels Sep 12, 2020
@abn abn requested a review from sdispater September 12, 2020 14:45
@dekoza
Copy link

dekoza commented Sep 13, 2020

Can I do anything to help this patch reach production asap? It's among the top fixes on my "urgently needed" list.

@dekoza
Copy link

dekoza commented Sep 15, 2020

This works like a charm. Dependencies that took 40 minutes in total (20 resolving + 20 locking) are now resolved in 18 seconds. Thank you @zweger !

Copy link
Member

@sdispater sdispater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @zweger!

This part of the code always felt clunky – even though it was doing the job – but I never had the time to improve it so I appreciate that you took the time to do it.

Thanks a lot!

@sdispater sdispater merged commit dfa5c0f into python-poetry:master Sep 15, 2020
Copy link

github-actions bot commented Mar 1, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/solver Related to the dependency resolver kind/enhancement Not a bug or feature, but improves usability or performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants