You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using pip's uninstall, either via pip uninstall or pip install --force-reinstall, I found that UninstallPathSet was generating thousands of calls to normalize_path(), the vast majority of which are being called on identical paths.
For instance, when running pip install --force-reinstall --no-deps .tox/.tmp/package/1/pip-23.1.dev0.tar.gz, I saw ~4000 calls to normalize_path().
~2500 were in calls to UninstallPathSet.add(), when normalizing the "head" of a file path. Since the vast majority of directories have several files in them, this meant we were repeating the path normalization of the "head" portion of the path.
~1500 were from calls to UninstallPathSet._permitted(), which calls is_local(). All but one of these were redundant, because is_local() calls normalize_path(sys.prefix), and sys.prefix shouldn't be changing while executing an uninstall.
In my testing on Windows, normalize_path() overwhelmingly spent its time calling realpath(). On Linux-based filesystems, realpath() might be a fast function, but it's more expensive on Windows, and all these calls were adding nearly 1 second of time to the uninstall.
Expected behavior
I would expect pip's uninstall logic to not normalize the same paths hundreds/thousands of times during the scope of a single uninstall/reinstall operation, degrading performance.
Instead, I would expect to see some level of caching as to not harm performance disproportionately on Windows platforms.
Description
When using pip's uninstall, either via
pip uninstall
orpip install --force-reinstall
, I found thatUninstallPathSet
was generating thousands of calls tonormalize_path()
, the vast majority of which are being called on identical paths.For instance, when running
pip install --force-reinstall --no-deps .tox/.tmp/package/1/pip-23.1.dev0.tar.gz
, I saw ~4000 calls tonormalize_path()
.UninstallPathSet.add()
, when normalizing the "head" of a file path. Since the vast majority of directories have several files in them, this meant we were repeating the path normalization of the "head" portion of the path.UninstallPathSet._permitted()
, which callsis_local()
. All but one of these were redundant, becauseis_local()
callsnormalize_path(sys.prefix)
, andsys.prefix
shouldn't be changing while executing an uninstall.In my testing on Windows,
normalize_path()
overwhelmingly spent its time callingrealpath()
. On Linux-based filesystems,realpath()
might be a fast function, but it's more expensive on Windows, and all these calls were adding nearly 1 second of time to the uninstall.Expected behavior
I would expect pip's uninstall logic to not normalize the same paths hundreds/thousands of times during the scope of a single uninstall/reinstall operation, degrading performance.
Instead, I would expect to see some level of caching as to not harm performance disproportionately on Windows platforms.
pip version
23.1
Python version
3.11
OS
Windows 11
How to Reproduce
python -m pip install --force-reinstall <path to the tar.gz you downloaded
normalize_path()
.Output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: