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

Defer import of zipp #502

Merged
merged 3 commits into from
Sep 11, 2024
Merged

Defer import of zipp #502

merged 3 commits into from
Sep 11, 2024

Conversation

danielhollas
Copy link
Contributor

Impoting zipp takes between 2-4 ms on my machine, which is at least 10% of overall import time of the importlib_metadata package (depending on Python version). Since this package is only used in a single code path it makes sense to defer it.

image

To estimate the cost of repeatedly calling import zipp I ran

python -m timeit -s "import zipp"  "import zipp"
5000000 loops, best of 5: 59.9 nsec per loop

(this is with cpython main branch)

Since this is in a codepath that reads a zipfile from disk, this overhead is negligible.

@jaraco
Copy link
Member

jaraco commented Sep 11, 2024

I'm starting to feel like a frog being slowly boiled. I'm seeing repeated optimizations like this being handled piecemeal, and each time I do, I need to go through the same process: point out that there's a systemic problem that has no solution, ensure there's a comment protecting the change and linking to the motivation, then merge and roll out the change. </rant>

Looks good. I'll add the comment linking back to the motivation and analysis (here). Thanks for the contrib.

@jaraco jaraco merged commit 58832f2 into python:main Sep 11, 2024
12 checks passed
@danielhollas danielhollas deleted the defer-zipp branch September 11, 2024 14:06
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 this pull request may close these issues.

2 participants