-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Process "multi" strings in compiled regexes 4 or 2 chars at a time when possible #1654
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jkotas
reviewed
Jan 12, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Jan 12, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Jan 12, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Jan 12, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Outdated
Show resolved
Hide resolved
It sounds reasonable to me. The high-performance parsers always end up using pattern like this. The convenience methods like StartsWith won't cut it. |
ac1222e
to
b756972
Compare
jkotas
approved these changes
Jan 13, 2020
jkotas
reviewed
Jan 13, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Outdated
Show resolved
Hide resolved
…en possible When we encounter a series of characters in a regex pattern, we emit a comparison check per character. This updates that codegen to compare 2 or 4 characters at a time, when possible. In general these sequences are not long, but they can easily be a handful of characters, and comparing with ints and longs instead of chars slightly improves both throughput and the size of the IL and JIT'd asm.
And add a test.
Avoids potentially very long generated Go methods and the resulting long JIT times and potentially stack overflows at invocation time. Prior to this change, a test added for 100K-long string takes a very long time to run and then stack overflows, whereas with this change it's very fast.
c830fbe
to
155135a
Compare
danmoseley
reviewed
Jan 13, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Show resolved
Hide resolved
danmoseley
reviewed
Jan 13, 2020
src/libraries/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs
Outdated
Show resolved
Hide resolved
danmoseley
reviewed
Jan 13, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Show resolved
Hide resolved
danmoseley
approved these changes
Jan 13, 2020
am11
reviewed
Jan 13, 2020
...libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCompiler.cs
Show resolved
Hide resolved
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When we encounter a series of characters in a regex pattern, we emit a comparison check per character. This updates that codegen to compare 2 or 4 characters at a time, when possible. In general these sequences are not long, but they can easily be a handful of characters, and comparing with ints and longs instead of chars slightly improves both throughput and the size of the IL and JIT'd asm.
@jkotas, any concerns with the change (philosophically due to the Unsafe usage, or otherwise)? Note that I first used StartsWith, but the overhead from that was very pronounced, with the cross-over point not being until around 40 or so characters.
Trivial microbenchmark:
Contributes to #1349