Skip to content
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

[BUG] Importing setuptools is slow and takes nearly half a second #3441

Open
jiasli opened this issue Jul 12, 2022 · 3 comments
Open

[BUG] Importing setuptools is slow and takes nearly half a second #3441

jiasli opened this issue Jul 12, 2022 · 3 comments

Comments

@jiasli
Copy link

jiasli commented Jul 12, 2022

setuptools version

63.1.0

Python version

3.10.5

OS

Windows

Additional environment information

No response

Description

Importing setuptools is slow and takes nearly half a second. This imposes significant performance impact on CLI applications (Azure/azure-cli#23177).

Expected behavior

Importing setuptools should be fast.

How to Reproduce

import setuptools

Output

python -X importtime -c "import setuptools" 2>perf.log ; python -m tuna .\perf.log

image

Without setuptools, importing distutils is pretty fast:

python -X importtime -c "import distutils" 2>perf.log ; python -m tuna .\perf.log

image

@jiasli jiasli added bug Needs Triage Issues that need to be evaluated for severity and status. labels Jul 12, 2022
@yonzhan
Copy link

yonzhan commented Jul 12, 2022

Good catch!

@abravalheri
Copy link
Contributor

abravalheri commented Jul 12, 2022

Hi @jiasli thank you very much for the study. Would you like to suggest any PRs tackling this issue?

For Python <= 3.12, _distutils_hack is still necessary, but probably for Python >= 3.12 that can be an easy gain.

I think we can also delay the import of unittest.mock in distutils/_msvccompiler.py, but that would have to be addressed as a PR to the pypa/distutils repository.

Currently the plan is to remove pkg_resources and we have been working continuously on this direction (this should provide some performance improvements). Unfortunately, it is not something we can modify quickly.

@jiasli
Copy link
Author

jiasli commented Jul 12, 2022

Thanks lot @abravalheri for the analysis.

Would you like to suggest any PRs tackling this issue?

I would certainly like to, but sadly I am not an expert on the delicate implementation of Python infrastructures. 🤣

Currently the plan is to remove pkg_resources and we have been working continuously on this direction (this should provide some performance improvements). Unfortunately, it is not something we can modify quickly.

This will certainly make setuptools significantly faster. We spent lots of effort getting rid of pkg_resources (Azure/azure-cli#14372, Azure/azure-cli#14905), but now it's back via setuptools. 😂

If setuptools can be as fast as the old distutils, that would really be helpful!

@abravalheri abravalheri added enhancement help wanted and removed bug Needs Triage Issues that need to be evaluated for severity and status. labels Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants