-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a set for TargetPython.get_tags for performance #12204
Merged
Merged
Conversation
This file contains 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
This speeds up a representative pip-compile by about 40% ``` λ hyperfine -w 1 -M 3 -p 'rm req.txt || true' 'python -m piptools compile req.in --output-file req.txt --strip-extras --resolver=backtracking' Benchmark 1: python -m piptools compile req.in --output-file req.txt --strip-extras --resolver=backtracking Time (mean ± σ): 28.552 s ± 2.552 s [User: 20.477 s, System: 1.547 s] Range (min … max): 26.446 s … 31.390 s 3 runs λ hyperfine -w 1 -M 3 -p 'rm req.txt || true' 'python -m piptools compile req.in --output-file req.txt --strip-extras --resolver=backtracking' Benchmark 1: python -m piptools compile req.in --output-file req.txt --strip-extras --resolver=backtracking Time (mean ± σ): 17.570 s ± 0.450 s [User: 11.537 s, System: 1.345 s] Range (min … max): 17.095 s … 17.989 s 3 runs ``` This makes the set.isdisjoint operation done over here much cheaper: https://github.com/pypa/pip/blob/593b85f4a/src/pip/_internal/models/wheel.py#L92 The reason for this is because a Python usually has a lot of supported tags. The Python I used above has 2000 supported tags! Whereas a wheel usually only has one or two file tags. The CPython code will unfortunately iterate over all 2000 tags to check if there's a match. Only if the other collection is a set will CPython think to swap the operands to iterate over the shorter collection: https://github.com/python/cpython/blob/35963da40f/Objects/setobject.c#L1352
hauntsaninja
changed the title
Use a set for TargetPython.get_tags
Use a set for TargetPython.get_tags for performance
Aug 4, 2023
uranusjr
reviewed
Aug 4, 2023
Oh, also note I tried narrowing the type on |
uranusjr
approved these changes
Aug 4, 2023
I don’t see why we need to narrow it though. Iterable seems just fine to me. |
pradyunsg
approved these changes
Aug 6, 2023
hauntsaninja
added a commit
to hauntsaninja/pip
that referenced
this pull request
Aug 6, 2023
This would have caught an issue I had when writing pypa#12204
cosmicexplorer
pushed a commit
to cosmicexplorer/pip
that referenced
this pull request
Aug 9, 2023
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.
This makes a representative pip-compile about 1.6x faster
This makes the set.isdisjoint operation done over here much cheaper: https://github.com/pypa/pip/blob/593b85f4a/src/pip/_internal/models/wheel.py#L92
The reason for this is because a Python usually has a lot of supported tags. The Python I used above has 2000 supported tags! Whereas a wheel usually only has one or two file tags.
The CPython code will unfortunately iterate over all 2000 tags to check if there's a match. Only if the other collection is a set will CPython think to swap the operands to iterate over the shorter collection: https://github.com/python/cpython/blob/35963da40f/Objects/setobject.c#L1352