Skip to content

gh-109653: Improve import preformance of tkinter library with lazy imports#148409

Open
sharktide wants to merge 9 commits intopython:mainfrom
sharktide:patch-2
Open

gh-109653: Improve import preformance of tkinter library with lazy imports#148409
sharktide wants to merge 9 commits intopython:mainfrom
sharktide:patch-2

Conversation

@sharktide
Copy link
Copy Markdown
Contributor

@sharktide sharktide commented Apr 11, 2026

Similar to #109789 but for Tkinter
EDIT: I can’t generate a direct comparison graph currently, but expect a 20-30% performance increase.

@sharktide sharktide marked this pull request as ready for review April 12, 2026 01:58
@sharktide
Copy link
Copy Markdown
Contributor Author

cc @AlexWaygood


import _tkinter # If this fails your Python may not be configured for Tk
lazy import sys
lazy import types
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_magic_re = re.compile(r'([\\{}])')
_space_re = re.compile(r'([\s])', re.ASCII)
def _get_magic_re():
"""Internal function."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this docstring (and below) doesn't add any info. (you can say that this function hides the re import to make it lazy

Suggested change
"""Internal function."""

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants