-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Regressions in System.Text.RegularExpressions.Tests.Perf_Regex_Industry_RustLang_Sherlock #80447
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Regressed via #78927 cc @MihaZupan |
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue DetailsRun Information
Regressions in System.Buffers.Tests.ReadOnlySequenceTests<Char>
Reprogit clone https://github.com/dotnet/performance.git
py .\performance\scripts\benchmarks_ci.py -f net8.0 --filter 'System.Buffers.Tests.ReadOnlySequenceTests<Char>*' PayloadsHistogramSystem.Buffers.Tests.ReadOnlySequenceTests<Char>.IterateGetPositionTenSegments
Description of detection logic
DocsProfiling workflow for dotnet/runtime repository
Regressions in System.Collections.ContainsKeyFalse<Int32, Int32>
Reprogit clone https://github.com/dotnet/performance.git
py .\performance\scripts\benchmarks_ci.py -f net8.0 --filter 'System.Collections.ContainsKeyFalse<Int32, Int32>*' PayloadsHistogramSystem.Collections.ContainsKeyFalse<Int32, Int32>.IDictionary(Size: 512)
Description of detection logic
DocsProfiling workflow for dotnet/runtime repository Run Information
Regressions in System.Text.RegularExpressions.Tests.Perf_Regex_Industry_RustLang_Sherlock
Reprogit clone https://github.com/dotnet/performance.git
py .\performance\scripts\benchmarks_ci.py -f net8.0 --filter 'System.Text.RegularExpressions.Tests.Perf_Regex_Industry_RustLang_Sherlock*' PayloadsHistogramSystem.Text.RegularExpressions.Tests.Perf_Regex_Industry_RustLang_Sherlock.Count(Pattern: "[a-zA-Z]+ing", Options: Compiled)
Description of detection logic
DocsProfiling workflow for dotnet/runtime repository
|
Looks like that PR introduced a lot of improvements dotnet/perf-autofiling-issues#11463 so feel free to close this issue if this single regression can be ignored |
It'd be good at least to understand why it regressed. |
Pattern: The diff (for the source generator at least) looks like ReadOnlySpan<char> span = inputSpan.Slice(pos);
for (int i = 0; i < span.Length; i++)
{
if (char.IsAsciiLetter(span[i]))
{
base.runtextpos = pos + i;
return true;
}
} int iteration = 0;
while ((uint)iteration < (uint)slice.Length && char.IsAsciiLetter(slice[iteration]))
{
iteration++;
} turned into int i = inputSpan.Slice(pos).IndexOfAny(Utilities.s_asciiLetters);
if (i >= 0)
{
base.runtextpos = pos + i;
return true;
} int iteration = slice.IndexOfAnyExcept(Utilities.s_asciiLetters);
if (iteration < 0)
{
iteration = slice.Length;
} Looking at what the offsets look like for the
The makeshift test code to generate the numbers above: gist. So in the vast majority of cases, we're seeing matches very close to the start of the input, so the overhead of calling into the vectorized path shows up. And with the compiled version the overhead of calling into (by "match" I just mean the loop exited, not an actual Regex match) |
Thanks for the investigation.
Hmm, that's an issue I hadn't previously noticed. So there's no devirtualization/inlining happening as part of the use of IndexOfAnyValues with Compiled? We may need to rethink that part. |
If I change the compiled version to use a
The traces look about how you'd expect As an experiment, I also added a fast-path to catch the
|
What happens if you remove the |
|
Thanks, so it is primarily the devirtualization/inlining. I'm not currently sure what to do about that. I did consider a fast-path like you experimented with where we check the next character directly and only subsequently fall back to IndexOfAny, but that just kicks the can down the road: you still have the same issue if the character is the second one, and the more checks you add, the more expensive you make it for the longer cases. Maybe just checking one is a sweet spot, but we'd need to do a lot of perf validation. |
Same regression on arm64: dotnet/perf-autofiling-issues#11579 |
Run Information
Regressions in System.Text.RegularExpressions.Tests.Perf_Regex_Industry_RustLang_Sherlock
Test Report
Repro
Payloads
Baseline
Compare
Histogram
System.Text.RegularExpressions.Tests.Perf_Regex_Industry_RustLang_Sherlock.Count(Pattern: "[a-zA-Z]+ing", Options: Compiled)
Description of detection logic
Docs
Profiling workflow for dotnet/runtime repository
Benchmarking workflow for dotnet/runtime repository
The text was updated successfully, but these errors were encountered: