Uh oh!
There was an error while loading. Please reload this page.
gh-109653: Improve import time of logging by lazy loading traceback - #112995
gh-109653: Improve import time of logging by lazy loading traceback#112995danielhollas wants to merge 2 commits into
logging by lazy loading traceback#112995Conversation
Delayed import of traceback results in ~16% speedup. Issue python#109653
jgeralnik
commented
Dec 12, 2023
The tests fail because you can't |
danielhollas
commented
Dec 12, 2023
@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
commented
Dec 14, 2023
@AlexWaygood this ended up being harder than I thought, see comments above. Unless you have any suggestions I'll close this. |
danielhollas
commented
Jan 24, 2024
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
commented
Jan 24, 2024
^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
commented
Jan 24, 2024
@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 :-) ) |
Lazy importing
tracebackmodule inloggingimproves the import time by ~15% on my machine (PGO-optimized build on Linux). Sincetracebackis 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 used a 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.