Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
mdboom wants to merge1 commit intopython:mainfrommdboom:python-startup-time

Conversation

mdboom
Copy link
Contributor

@mdboommdboom commentedApr 25, 2025
edited by bedevere-appbot
Loading

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.

Fidget-Spinner, StanFromIreland, chris-eibl, Wulian233, mikeshardmind, and sergey-miryanov reacted with rocket emoji
@mdboommdboom changed the titlegh-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 runtimeisinstance() checks on these protocols, and many users will use them without ever needing theisinstance() call.

@sergey-miryanov
Copy link
Contributor

I believe it is related to#118761

Copy link
Member

@AA-TurnerAA-Turner left a 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

@mdboom
Copy link
ContributorAuthor

@AA-Turner
Copy link
Member

@mdboom are you happy to merge this? It's still 'draft'.

A

@JelleZijlstra
Copy link
Member

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 inos.py.

@JelleZijlstra
Copy link
Member

It turns out it's not actually feasible to makeos.py also lazy-import_collections_abc, becauseos.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 importsio, but notos or pretty much anything else. I feel that's unlikely enough that it's not worth making this change.

@mdboom
Copy link
ContributorAuthor

It turns out it's not actually feasible to makeos.py also lazy-import_collections_abc, becauseos.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 importsio, but notos or pretty much anything else. I feel that's unlikely enough that it's not worth making this change.

Yeah, I agree. I think#132957 is the better solution. Closing.

@mdboommdboom closed thisApr 28, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AA-TurnerAA-TurnerAA-Turner approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@mdboom@JelleZijlstra@sergey-miryanov@AA-Turner

[8]ページ先頭

©2009-2025 Movatter.jp