Skip to content

gh-148762: Speed up multiline regexes anchored by ^#152339

Open
haampie wants to merge 4 commits into
python:mainfrom
haampie:hs/fix/multiline-caret
Open

gh-148762: Speed up multiline regexes anchored by ^#152339
haampie wants to merge 4 commits into
python:mainfrom
haampie:hs/fix/multiline-caret

Conversation

@haampie

@haampie haampie commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Multiline regexes of the form re.compile("^foo", re.MULTILINE) currently
fall into the generic search loop, which calls SRE(match) at every
position in the subject string. Since a ^-anchored (SRE_AT_BEGINNING_LINE)
pattern can only match at the start of the string or right after a linebreak,
we can instead jump from one line start to the next, skipping all the
intermediate positions.

Benchmarks show good improvements in runtime across UCS-1/2/4; full
numbers are in the issue.

haampie added 3 commits June 26, 2026 19:53
Signed-off-by: Harmen Stoppels <harmenstoppels@gmail.com>
Signed-off-by: Harmen Stoppels <harmenstoppels@gmail.com>
Signed-off-by: Harmen Stoppels <harmenstoppels@gmail.com>
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.

1 participant