Skip to content

Commit 47e82e2

Browse files
committed
Cache supported tags in resolver factory
I've observed get_supported() consume up to 10% of the installation step when installing many packages. Each call can take 1-5ms (presumably only on Linux due to the large number of supported tags) and there is one call for every lookup in the cache. As all of these calls are made with no arguments, the tags can be trivially queried in advance during factory initialization.
1 parent 0d1cde3 commit 47e82e2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

news/12712.feature.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve dependency resolution performance by caching platform compatibility
2+
tags during wheel cache lookup.

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def __init__(
121121
self._extras_candidate_cache: Dict[
122122
Tuple[int, FrozenSet[NormalizedName]], ExtrasCandidate
123123
] = {}
124+
self._supported_tags_cache = get_supported()
124125

125126
if not ignore_installed:
126127
env = get_default_environment()
@@ -608,7 +609,7 @@ def get_wheel_cache_entry(
608609
return self._wheel_cache.get_cache_entry(
609610
link=link,
610611
package_name=name,
611-
supported_tags=get_supported(),
612+
supported_tags=self._supported_tags_cache,
612613
)
613614

614615
def get_dist_to_uninstall(self, candidate: Candidate) -> Optional[BaseDistribution]:

0 commit comments

Comments
 (0)