Skip to content

Commit 1fc95f4

Browse files
committed
Cache AlreadyInstalledCandidate
Since the "Requirement already satisfied" message is printed during candidate preparation, instantiating the candidate multiple times result in excessive logging during intensive backtracking. By caching the already-installed candidates, each package is only prepared, and thus only logged once.
1 parent 643217b commit 1fc95f4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

news/9117.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
New resolver: The "Requirement already satisfied" log is not printed only once
2+
for each package during resolution.

src/pip/_internal/resolution/resolvelib/factory.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def __init__(
9696

9797
self._link_candidate_cache = {} # type: Cache[LinkCandidate]
9898
self._editable_candidate_cache = {} # type: Cache[EditableCandidate]
99+
self._installed_candidate_cache = {
100+
} # type: Dict[str, AlreadyInstalledCandidate]
99101

100102
if not ignore_installed:
101103
self._installed_dists = {
@@ -117,7 +119,11 @@ def _make_candidate_from_dist(
117119
template, # type: InstallRequirement
118120
):
119121
# type: (...) -> Candidate
120-
base = AlreadyInstalledCandidate(dist, template, factory=self)
122+
if dist.key in self._installed_candidate_cache:
123+
base = self._installed_candidate_cache[dist.project_name]
124+
else:
125+
base = AlreadyInstalledCandidate(dist, template, factory=self)
126+
self._installed_candidate_cache[dist.key] = base
121127
if extras:
122128
return ExtrasCandidate(base, extras)
123129
return base

0 commit comments

Comments
 (0)