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.
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
Fix slowness on Python 3.11 when updating an existing large environment. #12080
Fix slowness on Python 3.11 when updating an existing large environment. #12080
Changes from 2 commits
3eb3ddd
1269d0d
1a80e41
6aef932
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know why the
self.dist.version
line is slow? And how is it related to Python 3.11?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reiterate for clarity: it is not Python 3.11 per se, but it is because 3.11 uses
importlib.metadata
by default, instead ofpkg_resources
. You see the same on Python 3.10 with_PIP_USE_IMPORTLIB_METADATA=1
, and 3.11 is fast with_PIP_USE_IMPORTLIB_METADATA=0
.Getting one version is also not slow, but when doing
bin/pip install Plone -c https://dist.plone.org/release/6.0.5/constraints.txt
it gets called 440,106 times, so even milliseconds add up. I see that with the code from this PR,self.dist.version
only gets called one time per package, or 236 times total. Forsetuptools
alone,self.version
gets called 48,891 times.The difference is in the class of the distribution, and how it gets the version. It is either
pip._internal.metadata.pkg_resources.Distribution
orpip._internal.metadata.importlib._dists.Distribution
.I get confused following the
pkg_resources
case, but forimportlib
you get into the standard lib:That line 632 actually reads the
METADATA
file, making it slow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so the main difference is probably
pkg_resources
caches this value in-memory, whileimportlib.metadata
needs to re-parse the file every time. The fix makes sense then.It would be best to modify the news fragment to reflect that this is about
importlib.metadata
(and not 3.11 per se), and when pip repeatedly accesses an already-installed distribution (and not all “large environments” are affected, only if that environment has a lot of overlaps with the to-be-installed requirement set).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (and rebased on main).