Skip to content

Commit

Permalink
Cache supported tags in resolver factory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ichard26 committed Jun 8, 2024
1 parent 86b8b23 commit 24e23bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions news/12712.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve installation performance by caching platform compatibility tags during
cache lookup.
3 changes: 2 additions & 1 deletion src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def __init__(
self._extras_candidate_cache: Dict[
Tuple[int, FrozenSet[NormalizedName]], ExtrasCandidate
] = {}
self._supported_tags_cache = get_supported()

if not ignore_installed:
env = get_default_environment()
Expand Down Expand Up @@ -608,7 +609,7 @@ def get_wheel_cache_entry(
return self._wheel_cache.get_cache_entry(
link=link,
package_name=name,
supported_tags=get_supported(),
supported_tags=self._supported_tags_cache,
)

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

0 comments on commit 24e23bd

Please sign in to comment.