Skip to content

gh-148762: speed up SRE_AT_BEGINNING_LINE regexes#148778

Open
haampie wants to merge 1 commit intopython:mainfrom
haampie:hs/fix/multiline-caret
Open

gh-148762: speed up SRE_AT_BEGINNING_LINE regexes#148778
haampie wants to merge 1 commit intopython:mainfrom
haampie:hs/fix/multiline-caret

Conversation

@haampie
Copy link
Copy Markdown
Contributor

@haampie haampie commented Apr 19, 2026

SRE(search) lacks a fast-forward for multiline regexes like

re.compile("^foo", re.MULTILINE)

even though it has a fast prefix scan for regexes like foo.

The current implementation does a character-by-character loop that calls
SRE(match) each iteration, leading to a lot of overhead.

This commit ensures SRE(match) is only called right after a newline
character, leading to a ~10x speedup in a representative benchmark.

Signed-off-by: Harmen Stoppels <harmenstoppels@gmail.com>
@haampie haampie force-pushed the hs/fix/multiline-caret branch from a59b863 to 22f498f Compare April 23, 2026 15:20
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