Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mdboom
Copy link
Contributor

@mdboom mdboom commented Apr 25, 2025

This improves the time of a no-site.py startup by 12%, i.e.

python -c pass -S

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.

@mdboom mdboom changed the title gh-127648: Improve Python startup time by ~12% gh-132952: Improve Python startup time by ~12% Apr 25, 2025
@JelleZijlstra
Copy link
Member

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.

@sergey-miryanov
Copy link
Contributor

I believe it is related to #118761

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants