-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
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
| commands_order = [ | |
| InstallCommand, | |
| DownloadCommand, | |
| UninstallCommand, | |
| FreezeCommand, | |
| ListCommand, | |
| ShowCommand, | |
| CheckCommand, | |
| ConfigurationCommand, | |
| SearchCommand, | |
| WheelCommand, | |
| HashCommand, | |
| CompletionCommand, | |
| DebugCommand, | |
| HelpCommand, | |
| ] # type: List[Type[Command]] |
And then import only the command class it needs after parsing the command name:
pip/src/pip/_internal/__init__.py
Line 76 in ddfa401
| command = commands_dict[cmd_name](isolated=("--isolated" in cmd_args)) |
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.