Skip to content

Introduce new API in resolvelib to Optimize Pip's Dependency Resolution #12497

@notatallshaw

Description

@notatallshaw

What's the problem this feature will solve?

Pip's dependency resolution process, particularly in complex backtracking scenarios, currently faces performance issues due to repetitive calculations, leading to O(n^2) complexity. This issue arises when checking if a "name" is part of a cause but also hinders the implementation of more complex checks, as they would slow down simple backtracking scenarios.

Describe the solution you'd like

The solution proposes adding a new abstract method, filter_unsatisfied_names, in resolvelib, to be implemented by Pip. This method is designed to work alongside the existing get_preference method, refining the backtracking process during dependency resolution.

  • filter_unsatisfied_names pre-filters unsatisfied names before they are processed by get_preference.
  • Unlike get_preference, which is called once for each name, filter_unsatisfied_names is called only once per backtracking round.
  • All unsatisfied names are provided to filter_unsatisfied_names, in contrast to get_preference, which receives one name at a time.
  • Hence filter_unsatisfied_names is able to short-circuiting checks.
  • And filter_unsatisfied_names can determine if multiple names are important to backtrack on simultaneously.

Alternative Solutions

  • Enhancing get_preference: Improvements to this method could offer some benefits, but it would struggle to enable complex backtracks without imposing performance penalties on simple backtracks.
  • Implementing Caching: While caching can reduce redundant work, it might lead to increased memory usage and added complexity.

Additional context

I am not tied to the name filter_unsatisfied_names or even to this specific approach, as long as it's possible to filter unsatisfied names more than one at a time.

A PR is open on the resolvelib side, but it is unlikely to ever be merged without buy-in from Pip maintainers: sarugaku/resolvelib#145

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions