-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-132952: Improve Python startup time by ~12% #132956
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
Conversation
This only helps the I think it's pretty defensible to lazy-import here as well as in os.py though; the import is only needed for runtime |
I believe it is related to #118761 |
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.
Especially as the intent is for these to be Protocol classes, I agree with Jelle that deferring makes sense.
A
Confirmation on controlled benchmarking hardware that this is effective: https://github.com/faster-cpython/benchmarking-public/blob/main/results/bm-20250425-3.14.0a7%2B-9fc1238/bm-20250425-linux-x86_64-mdboom-python_startup_time-3.14.0a7%2B-9fc1238-vs-base.svg |
@mdboom are you happy to merge this? It's still 'draft'. A |
If we merge this, let's try to make it so |
It turns out it's not actually feasible to make That means (if we merge #132957) this PR only helps in the case where the user used |
Yeah, I agree. I think #132957 is the better solution. Closing. |
This improves the time of a no-
site.py
startup by 12%, i.e.I'm not strongly of the opinion this should be merged (hence the draft PR), since there are probably all kinds of other places where "lazy importing" could be used to improve startup time that don't improve readability. On the other hand, it's a fairly large regression from 3.13.x that we may want to avoid.
python_startup_no_site
benchmark #132952