Fixed #36729 -- Pre-compiled all regular expressions #20096
+156
−83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trac ticket number
ticket-36729
Branch description
This PR moves any remaining regexes loaded at runtime to being pre-compiled, either using
re.compileor_lazy_re_compile.I've also added a note to the coding style to mention that this should be the default going forwards.
One of the downsides of extracting patterns to the module level is that they now need a name. I've had a go in some places of putting something sensible, but others are named just to extract them, and could do with some other brains 🧠 input on some sensible naming.
I've not run any benchmarks, but I'd expect this to make varying amounts of difference across the codebase. I've intentionally switched between lazy and non-lazy compilation based on my own thoughts as to how frequently and likely a pattern is to be used. Some people may disagree - I'm not especially tied to any of the decisions.
The process for doing this was to find-and-replace each of the top-level
refunctions which operate on patterns, where the pattern isn't built based on input at runtime. I think I caught them all, but can't hurt to check!Checklist
mainbranch.