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

Regex compiler / source generator can use IndexOf to speed up lazy loop #62669

Closed
stephentoub opened this issue Dec 11, 2021 · 1 comment · Fixed by #63428
Closed

Regex compiler / source generator can use IndexOf to speed up lazy loop #62669

stephentoub opened this issue Dec 11, 2021 · 1 comment · Fixed by #63428
Assignees
Milestone

Comments

@stephentoub
Copy link
Member

stephentoub commented Dec 11, 2021

In greedy char loops, if the loop is followed by a known literal, when backtracking we LastIndexOf to find the next possible place to try to continue the match, rather than just backing up one char at a time. We can do the opposite for lazy char loops: rather than incrementing the position one char at a time, we can IndexOf{Any} for the following literal to find the next possible place to continue matching. In the case of a .? in Singleline, we can use IndexOf for the subsequent literal; in the case of a .? when not in Singeline, we can use IndexOfAny('\n', literal).

@ghost
Copy link

ghost commented Dec 11, 2021

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Issue Details

In greedy char loops, if the loop is followed by a known literal, when backtracking we LastIndexOf to find the next possible place to try to continue the match, rather than just backing up one char at a time. We can do the opposite for lazy char loops: rather than incrementing the position one char at a time, we can IndexOf for the following literal to find the next possible place to continue matching.

Author: stephentoub
Assignees: -
Labels:

area-System.Text.RegularExpressions, tenet-performance

Milestone: 7.0.0

@stephentoub stephentoub changed the title Regex source generator can use IndexOf to speed up lazy loop Regex compiler / source generator can use IndexOf to speed up lazy loop Dec 13, 2021
@stephentoub stephentoub self-assigned this Dec 31, 2021
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 6, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 15, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Feb 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant