Don't convert versions to strings when using importlib.metadata backend#13660
Conversation
60b96af to
8a45605
Compare
|
While the importlib-metadata backend is indeed the default on Python 3.11+, the legacy pip/src/pip/_internal/metadata/__init__.py Lines 30 to 46 in e18a82f I suspect that the number of users actually using pkg_resources on Python 3.11 or higher is extremely low1 though. Footnotes
|
😢 Do you know if there is a way we can detect which backend is being used? |
|
Note we have a deprecation in place to remove the pkg_resources backend in 26.3 (when we drop python 3.10 actually). |
Okay, this was actually simple, you can directly look at |
3fe9c2f to
bb0d5f5
Compare
If I am understanding the following notice correctly as of Python 3.11 pip will no longer use
pkg_resources._vendor.packaging.version.Versionin any situation (it doesn't seem to by default anyway), and can only usepackaging.version.Version:pip/src/pip/_internal/metadata/__init__.py
Lines 63 to 67 in e18a82f
Skipping stringification and Version creation saves a non-trivial amount of time when heavily backtracking. In the pathological resolver benchmark I'm using to find hotspots and bottlenecks this change reduces the number of
Versionobjects created from ~3.37 million to ~2.30 million.Before and after call graphs:
Details
Before:
After: