gh-117865: Defer import of re in ast by JelleZijlstra · Pull Request #119546 · python/cpython
How much does this speedup the import of inspect? I wouldn't expect it to do much on its own, since inspect itself also imports re. Or is the idea that this could be done in combination with some of the changes in #119526?
(Though it's probably worth doing even if it just speeds up the import of ast. I guess I was looking at it through the lens of the github issue it was attached to.)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locally for me this cuts about 20% off the import time for ast (0.0036s -> 0.0029s), so this seems worth doing. This is especially true since the _splitlines_no_ff function is only ever used in get_source_segment, which is one of the lesser-used ast-module APIs
estyxx pushed a commit to estyxx/cpython that referenced this pull request
This is used only by ast.get_source_segment(), so it seems sensible to avoid importing it. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>