Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@RealOrangeOne
Copy link
Member

Trac ticket number

ticket-36729

Branch description

This PR moves any remaining regexes loaded at runtime to being pre-compiled, either using re.compile or _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 re functions 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

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@RealOrangeOne RealOrangeOne force-pushed the 36729-precompile-regexes branch from 63cd1c3 to 3ed8fdc Compare November 14, 2025 11:17
@RealOrangeOne RealOrangeOne force-pushed the 36729-precompile-regexes branch from 3ed8fdc to 29b70d7 Compare November 14, 2025 11:27
@nessita nessita added benchmark Apply to have ASV benchmarks run on a PR python-matrix labels Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark Apply to have ASV benchmarks run on a PR python-matrix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants