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
Use __getattr__
for all package imports, improve import time
#7947
Conversation
Deploying with Cloudflare Pages
|
__getattr__
for all imports from __init__.py
__getattr__
for all package imports, improve import time
__getattr__
for all package imports, improve import time__getattr__
for all package imports, improve import time
Awesome thank you, definitely a step in the right direction!
Do you see a way to reduce the import cost of |
That last commit helped a little!
|
@ofek I've got rid of import time import of If you see anything else, let me know. |
I think this is ready. Please review @sydney-runkle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! LGTM. Solid performance improvements 🏎️
One question - does this merit any update to the docs? I'm guessing not, that a change log entry is enough, but just wanted to check. I'm pretty sure 99% of users aren't going to be digging around for this kind of info.
I don't think anything in logs, I think it merits a prominent notice in the release notes and a tweet from me now saying we're doing it. AFAIK this shouldn't affect anyone and I made the change in few steps to see, but the only real answer is to release it and see. |
Out of curiosity, how will the practice of being conscious about import time be maintained during continued development? |
I've added unit tests that that those modules aren't imported in specific cases, e.g. The longer term solution is all down to @art049 - we should use Codspeed for continuous profile of stuff we care about like import time, as we do on pydantic-core. |
Change Summary
This means
pydantic/__init__.py
is now lazy about all imports using__getattr__
.Import performance changes:
Before
After
Tuna output:
Related issue number
As promised in #7423 (comment).
Checklist
Selected Reviewer: @sydney-runkle