-
-
Notifications
You must be signed in to change notification settings - Fork 49
Improve import time #326
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
Comments
Just following up to gauge interest in making this happen. cc @jaraco |
Thanks for the proposal! I'm open to these improvements, especially where the value exceeds the drawbacks. Here's what I recommend:
It's all relative. This library dramatically improved import time over
No need, but let's definitely collect per-commit differences in some environment (CPython, any OS).
I'll be resistant to this change, especially if it degrades the cognitive benefits of separation of concerns, but feel free to propose it.
Definitely! And once contributed here, it will get rolled into CPython as well (as Feel free also to contribute any bug fixes as well (in separate PRs). |
I'll get on it, then. We'll see how this goes. |
importlib_resources
currently takes a while to import. From rough local testing with whatever Python versions I have installed, the figures are something like this:(The numbers were obtained by cloning the main branch and running
<python> -m timeit -n 1 -r 1 -- "import importlib_resources"
a bunch without a venv, just raw import without site-packages baggage. If need be, I can get more precise results.)For context on my perspective, most of the standard library modules that I've interacted with take a fraction of that time.
To improve this, I've been messing about and managed to get the figures down by at least 7x:
This improvement mostly comes from the following:
inspect
usage with a cheaper pattern that other stdlib modules use.inspect.get_annotations
ortyping.get_type_hints
).importlib_metadata
's, imo).That's all without a few tricks employed by other standard library modules like
importlib._bootstrap
andimportlib.util
, e.g. avoiding importingfunctools
andcontextlib
in exchange for slightly more verbose code. Doing those would make the improvement at least 10x.Considering this is a "foundational" library (meant to partially replace the widely used
pkg_resources
) and is also in the standard library, and the potential for improvement is so large with a pretty small amount of effort, I was wondering if there would be interest in improving this, and if so, whether it would be acceptable for me to attempt that by upstreaming some of my work?P.S. The branch I've been experimenting on is here if you're curious, though it does too many things (e.g. fixes some bugs, completes the typing, adds unnecessary personalization) for me to consider making a PR with it directly. Makes more sense to do things piecemeal.
The text was updated successfully, but these errors were encountered: