| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
This only helps the -S startup because site.py imports os.py which also imports _collections_abc. I think it's pretty defensible to lazy-import here as well as in os.py though; the import is only needed for runtime isinstance() checks on these protocols, and many users will use them without ever needing the isinstance() call. |
Sorry, something went wrong.
There was a problem hiding this comment.
Especially as the intent is for these to be Protocol classes, I agree with Jelle that deferring makes sense.
A
Sorry, something went wrong.
|
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 |
Sorry, something went wrong.
|
@mdboom are you happy to merge this? It's still 'draft'. A |
Sorry, something went wrong.
|
If we merge this, let's try to make it so _collections_abc isn't imported on normal (without -S) startup too, so this helps in a bit more realistic cases. It should be easy to defer the import in os.py. |
Sorry, something went wrong.
|
It turns out it's not actually feasible to make os.py also lazy-import _collections_abc, because os.Environ inherits from _collections_abc.MutableMapping. That means (if we merge #132957) this PR only helps in the case where the user used -S and imports io, but not os or pretty much anything else. I feel that's unlikely enough that it's not worth making this change. |
Sorry, something went wrong.
Yeah, I agree. I think #132957 is the better solution. Closing. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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.