Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp: Optimize for inputs that are provably too short #31329

Closed
sylvinus opened this issue Apr 7, 2019 · 5 comments
Closed

regexp: Optimize for inputs that are provably too short #31329

sylvinus opened this issue Apr 7, 2019 · 5 comments

Comments

@sylvinus
Copy link
Contributor

@sylvinus sylvinus commented Apr 7, 2019

I'm following up on my work on regexp performance from #21463 with a couple smaller patches. This one is somewhat related.

For many patterns we can compute the minimum length of the input at compile time. For instance, an HTTP router might use a pattern like \/(path1|path2)\/(.+)\.html, which has a minimum input length of 13 bytes.

If the input is shorter than that, as may happen quite frequently, we can return early and get a huge speedup.

Some benchmarks are included in the CL.

Feedbacks welcome!

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 7, 2019

Change https://golang.org/cl/171023 mentions this issue: regexp: optimize for provably too short inputs

@bcmills
Copy link
Member

@bcmills bcmills commented Apr 8, 2019

CC @rsc @matloob for regexp.

@dgryski
Copy link
Contributor

@dgryski dgryski commented Apr 8, 2019

It's interesting to note that Perl's regex engine contains a number of these kinds of fail-fast optimizations: https://perldoc.perl.org/perlreguts.html#Peep-hole-Optimisation-and-Analysis

@sylvinus
Copy link
Contributor Author

@sylvinus sylvinus commented Apr 8, 2019

@dgryski yes it does! I plan to implement many of them if there's interest.

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 6, 2019

Change https://golang.org/cl/188800 mentions this issue: regexp: optimize for provably too long inputs

@golang golang locked and limited conversation to collaborators Aug 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.