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 intopython:mainfrom
logging by lazy loading traceback#112995Conversation
Delayed import of traceback results in ~16% speedup. Issue python#109653
|
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. CC @AlexWaygood |
|
^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 :-) ) |
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.