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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolution speed improvement #3839

Merged
merged 4 commits into from Jul 11, 2021
Merged

Resolution speed improvement #3839

merged 4 commits into from Jul 11, 2021

Conversation

jguice
Copy link
Contributor

@jguice jguice commented Mar 27, 2021

Pull Request Check List

Resolves (at least some of): #2094

  • Added Updated tests for changed code.
  • Updated documentation for changed code. (N/A)

This PR contains a fix for slow dependency resolution that's been in use successfully since August 2020. I've updated it for the latest master code as of this writing. All tests are passing and only required some ops re-ordering due to the nature of the fix.

The root problem was that the final (interim) dependency tree had many redundant nodes (especially in projects with deep dependency hierarchies). This fix skips "seen" nodes which drastically speeds up many scenarios.

I encourage everyone with resolution speed issues to try this version from my fork (until hopefully this PR gets accepted). Please comment on this PR if you find any new issues using this version, and also if you experience speed improvements. 馃殌

@abn abn requested a review from sdispater March 27, 2021 21:00
@abn
Copy link
Member

abn commented Mar 27, 2021

LGTM. Might require a peek from @sdispater though.

@@ -417,6 +420,12 @@ def __init__(
def reachable(self) -> List["PackageNode"]:
children: List[PackageNode] = []

# skip already traversed packages
if self.package in self.seen:

Choose a reason for hiding this comment

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

Just an idea: could/should this check be moved to https://github.com/python-poetry/poetry/pull/3839/files#diff-c2fd13b8785fbb20817a8c0e4ce7425249eaa6be7a4faeb1fad846cadccfbfadR363 (part of the depth-first-search method implementation)?

Something along the lines of:

    ...
    for neighbor in node.reachable():
        back_edges[neighbor.id].append(node)
        if neighbor.id in visited:
            continue
        ...

(it feels like the check is an optimization of the DFS algorithm, which is why I wondered if it could live closer to the dfs_visit method rather than being attached to the nodes that the search runs over. I haven't performance evaluated this though, nor checked whether it would behave the same way as your change)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jayaddison quite possibly! I kept the fix as close to the original as possible from August 2020 (before the DFS was more clearly formalized in the code). I expect that the regular authors/maintainers who are more familiar with the internal structure and flow will know where to best plug this fix in. 馃檪

@lainisourgod
Copy link

@jguice I just tried your version and the latest master, and the latest works faster for me somehow. Maybe some poetry-core refactor affected speed and resolved some of the problems you worked with?

@janjur
Copy link

janjur commented May 22, 2021

Guys, dozens of dev teams are dying while waiting for resolution of this issue. Step it up pls.

@jguice
Copy link
Contributor Author

jguice commented Jul 8, 2021

@meandmymind be sure to clear your cache between runs for the test to be more valid. I've found this to be both a combination of poetry cache clear commands and rm -rf ~/Library/Caches/pypoetry/* (the latter may take care of both, but just running the former I've still had downloaded packages in pypoetry/assets). I discovered this when I had a malformed zip file that clearing cache did not resolve. 馃槵

Also this fix is based off master (as of the PR) which has other unrelated changes that may be impacting speed.

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.

Looks good to me 馃憤 Thanks a lot!

@sdispater sdispater merged commit 40dc3ad into python-poetry:master Jul 11, 2021
@sdispater sdispater mentioned this pull request Jul 31, 2021
Copy link

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 Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants