[DO-NOT-MERGE] populate requirement.specifier on demand #13323
Closed
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.
I was looking at the distribution discovery performance improvements of #12308 and I realized that ~1/3 of packaging
Requirement
construction is spent on creating thespecifier
(SpecifierSet) attribute. It's expensive as each of the contained specifiers have to be hashed immediately.While the
specifier
attribute is accessed frequently, not all operations need it. For example,pip show six
sped up by ~20ms with 114 packages installed if modify packaging to populate thespecifier
attribute on-demand.@notatallshaw I'm curious to whether this has any impact on dependency resolution. While any requirement considered during dependency resolution is obviously going to require the the version specifier, there are a lot of requirements that aren't ever considered. Typically these are all of the requirements from extras.
For example, if I further modify packaging to keep track of how many
Requirement
objects are constructed and how many have theirspecifier
attribute materialize, I get 23/180 forpip install --dry-run --ignore-installed black pytest mypy nox
.If you have time, I'd be interested in whether this results in a measurable improvement.