-
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
Don't import the world when pip starts up #6692
Comments
Later PR's could move the modules needed for pip startup into a |
If in addition to the above, the following pip/src/pip/_internal/utils/misc.py Line 21 in ddfa401
to a different location (and |
Would we want to consider solutions like demandimport in the context of this issue? Just adding
this to the top of the |
Related to #4768. |
Personally, I think my preference would be to start out with simple, more explicit methods before relying on a third-party module like that. We haven't really tried basic things yet. As before, one of my concerns is that it could be masking / papering over issues that we could be solving more directly, and it would also maybe make the code harder to understand since the code wouldn't be behaving like people are accustomed to. |
I think it's because demandimport requires a particular style of import to get the benefit, which we don't use. (Specifically, we import functions and classes directly instead of importing only the module and accessing the function or class as an attribute of the module.) |
Address #6692: Only import a Command class when needed
@cjerdonek Can we close this? |
This was addressed by PR #6694. |
Currently, when pip starts up, it basically imports its entire code base and all vendored libraries and modules it depends on. This issue is for pip only to import what it needs.
It looks like a large part of this can be done pretty simply by changing
commands/__init__.py
not to import all the command classes:pip/src/pip/_internal/commands/__init__.py
Lines 27 to 42 in ddfa401
And then import only the command class it needs after parsing the command name:
pip/src/pip/_internal/__init__.py
Line 76 in ddfa401
This will require storing a mapping of command name to command class location and command "summary."
It looks like this would reduce the startup time by ~20% when I tried a quick test.
The text was updated successfully, but these errors were encountered: