perf(cache): use a set of tags for wheel cache lookup - #14122
Merged
Conversation
KRRT7
force-pushed
the
perf/cache-supported-tags-set
branch
from
June 29, 2026 18:05
a599034 to
95191c1
Compare
4 tasks
Co-authored-by: Richard Si <sichard26@gmail.com>
YakBizzarro
pushed a commit
to YakBizzarro/pip
that referenced
this pull request
Jul 9, 2026
This scales much better than using a list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
support_index_min()so cached wheel preference is unchangedfrozenset.isdisjoint(list)scans when many cached wheels are considered for the same source linkPerformance Model
isdisjoint(list)Hypothesis: repeated compatibility scans over the same supported-tag list are a meaningful share of
SimpleWheelCache.get()runtime when a cache directory contains many wheels for one project.Profile before the change confirmed this: in 20 cache lookups over 2,000 wheel candidates,
Wheel.supported()/frozenset.isdisjoint(list)accounted for about 4.8s of 5.2s cumulative runtime, with 52.9MTag.__hash__calls.After the change, the same profile no longer has
Wheel.supported()in the top cumulative entries; wheel filename parsing is the remaining dominant cost.Benchmark
Apple M3, 24 GiB RAM, CPython 3.14.5
Target workload:
SimpleWheelCache.get()selecting a cached wheel for one source link from 2,000 same-project cached wheel filenames. 1,999 candidates are unsupportedpy2-none-anywheels and the final candidate is supportedpy3-none-any. This represents cached wheel selection where pip must filter many cached builds before returning the best compatible wheel.6b0011b49(base)95191c130(head)I also ran
python -m timeitin the working branch environment:Reproduce the benchmark locally
Changelog
Added
news/14122.bugfix.rst.Stack
perf/cache-supported-tags-setmainExisting open performance PRs were checked and are independent of this change: #14108, #14106, #14088, #14103, #14045, #14026, and #13860.
Test plan
cProfileuv run ruff check src/pip/_internal/cache.py tests/unit/test_cache.pyuv run pytest tests/unit/test_cache.py -quv run pytest tests/unit/test_cache.py tests/unit/test_models_wheel.py -q