Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Delayed import of traceback results in ~16% speedup.Issuepython#109653
ghost commentedDec 12, 2023 • edited by ghost
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by ghost
Uh oh!
There was an error while loading.Please reload this page.
jgeralnik commentedDec 12, 2023
The tests fail because you can't |
@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? |
@AlexWaygood this ended up being harder than I thought, see comments above. Unless you have any suggestions I'll close this. |
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. |
^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 :) |
@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 :-) ) |
Uh oh!
There was an error while loading.Please reload this page.
Lazy importing
traceback
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.