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

Slow to import #394

Closed
Dreamsorcerer opened this issue Dec 20, 2021 · 3 comments · Fixed by #414
Closed

Slow to import #394

Dreamsorcerer opened this issue Dec 20, 2021 · 3 comments · Fixed by #414

Comments

@Dreamsorcerer
Copy link
Member

On my system, import aiohttp_debugtoolbar takes ~1.6s to run.

This seems excessive, and adds a noticeable amount of time to app reloading when developing with aiohttp-devtools.

@asvetlov
Copy link
Member

I'm curious, why?
Did you try python -X importtime ... to analyze?

@Dreamsorcerer
Copy link
Member Author

Not sure how to read importtime output, but viewing through tuna looks like this:
Screenshot 2021-12-20 at 21-15-17 tuna - import log

If I'm reading that correctly, it looks like most of the time is probably spent with this packages code:
https://github.com/aio-libs/aiohttp-debugtoolbar/blob/master/aiohttp_debugtoolbar/panels/versions.py#L12-L33

A secondary issue is gunicorn getting imported via aiohttp.workers. Maybe it would be best to remove the gunicorn workers from aiohttp/__init__.py in v4? Just require users to import the workers directly if needed (same for anything else that's having a noticeable impact on the import time).

@asvetlov
Copy link
Member

The main issue is pkg_resources, the famously slow package :)
I suggest replacing it with importlib.metadata.

Regarding gunicorn import -- yes. After upgrading the minimal required Python to 3.7 we can do __getattr__ trick, similar to concurrent.futures.

If you can find time for both improvements -- you are welcome!

Dreamsorcerer added a commit to aio-libs/aiohttp that referenced this issue Nov 20, 2022
See
aio-libs/aiohttp-debugtoolbar#394 (comment)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sviatoslav Sydorenko <sviat@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants