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-109653: Improve import time oflogging by lazy loadingtraceback#112995

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

Conversation

danielhollas
Copy link
Contributor

@danielhollasdanielhollas commentedDec 12, 2023
edited
Loading

Lazy importingtraceback module inlogging improves the import time by ~15% on my machine (PGO-optimized build on Linux). Sincetraceback is used here to handle exceptions, these code paths should by definition better be exceptional so lazy loading makes sense.

In order to avoid performance impacts, I have useda trick proposed in a similar PR. Perhaps this trick is not necessary here though since as mentioned above these code paths should not be hot.

TODO: Fix the failing test.

Delayed import of traceback results in ~16% speedup.Issuepython#109653
@ghost
Copy link

ghost commentedDec 12, 2023
edited by ghost
Loading

All commit authors signed the Contributor License Agreement.
CLA signed

@jgeralnik
Copy link

The tests fail because you can'timport traceback when python is shutting down (but logging can still be called - e.g. in adel function of a global object)

danielhollas reacted with heart emoji

@danielhollas
Copy link
ContributorAuthor

@jgeralnik oh, interesting, thank you! That would take me some time to figure out. So what you're saying is that this particular PR is doomed, we simply can't import traceback lazily? Or do you see some way around it?

@danielhollas
Copy link
ContributorAuthor

@AlexWaygood this ended up being harder than I thought, see comments above. Unless you have any suggestions I'll close this.

@danielhollas
Copy link
ContributorAuthor

The tests fail because you can't import traceback when python is shutting down (but logging can still be called - e.g. in a del function of a global object)

It seems that new modules can't be imported during Python shutdown, and the logging module needs to be available during shutdown so I don't see a way around this. Closing.

CC@AlexWaygood

@AlexWaygood
Copy link
Member

^Sorry for not getting to this earlier! Been unusually busy the last month or so :)

Yeah, the stuff that goes on when Python is shutting down is... scary. Agree with the decision to close this one :)

danielhollas reacted with heart emoji

@danielhollasdanielhollas deleted the import-logging-speedup branchJanuary 24, 2024 15:24
@danielhollas
Copy link
ContributorAuthor

@AlexWaygood no worries at all, thanks for the comment and review on#114509 🤝

It was interesting to poke at stdlib for the first time (and realizing, as always, that things are more complicated than originally thought :-) )

AlexWaygood reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@vsajipvsajipAwaiting requested review from vsajipvsajip will be requested when the pull request is marked ready for reviewvsajip is a code owner

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@danielhollas@jgeralnik@AlexWaygood

[8]ページ先頭

©2009-2025 Movatter.jp