gh-109653: Improve import preformance of tkinter library with lazy imports#148409
gh-109653: Improve import preformance of tkinter library with lazy imports#148409sharktide wants to merge 8 commits intopython:mainfrom
tkinter library with lazy imports#148409Conversation
Lib/tkinter/__init__.py
Outdated
| import enum | ||
| import sys | ||
| import types | ||
| lazy import collections |
There was a problem hiding this comment.
collections and enum modules will always be imported since they are used at module level, so it's pointless and misleading to make them lazy here.
You can verify which modules get imported by running
python -Ximporttime -c 'import tkinter'
You should also provide a benchmark, you can use the output from this command and visualize it with the tuna package.
There was a problem hiding this comment.
On it. I would have done the benchmark, but I don’t have access to a computer for the next ~24 hours (currently phone coding). (That’s why I labeled this PR as draft :))
There was a problem hiding this comment.
Yes, sorry, I noticed the Draft state only after I wrote the comment :-)
Lib/tkinter/__init__.py
Outdated
| TkVersion = float(_tkinter.TK_VERSION) | ||
| TclVersion = float(_tkinter.TCL_VERSION) | ||
|
|
||
| lazy import re |
There was a problem hiding this comment.
Please move to the top with the other imports
There was a problem hiding this comment.
Yes. I still need to get re out of __all__ however. Once everything is finished, I’ll remove the draft status from this PR
Similar to #109789 but for Tkinter