Addresses Regex Perf Issue 32764 by Alois-xx · Pull Request #32899 · dotnet/corefx (original) (raw)

@ViktorHofer
Benchmark.NET was a little funny to get it to use the compiled dlls and not the ones from the framework sdk. Here are the patched Results:

                        Method | N |         Mean |        Error |       StdDev | Allocated |
------------------------------ |-- |-------------:|-------------:|-------------:|----------:|
                      Original | 1 | 438,212.4 ns | 4,647.930 ns | 4,347.676 ns |       0 B |
                 CaseSensitive | 1 | 227,563.0 ns | 5,142.693 ns | 5,281.167 ns |       0 B |
 CaseSensitiveCultureInvariant | 1 | 215,541.1 ns | 1,187.442 ns | 1,110.734 ns |       0 B |
          SimplifiedExpression | 1 |   1,525.5 ns |    11.969 ns |    11.195 ns |       0 B |
      Case_Sensitive_Substring | 1 |     691.5 ns |     4.897 ns |     4.581 ns |       0 B |

And here the baseline version where I did revert the changes of my commit to really measure the impact of only my change:

                        Method | N |           Mean |         Error |        StdDev | Allocated |
------------------------------ |-- |---------------:|--------------:|--------------:|----------:|
                      Original | 1 | 1,055,537.2 ns | 31,271.169 ns | 36,011.922 ns |       0 B |
                 CaseSensitive | 1 |   216,579.6 ns |  1,827.153 ns |  1,709.119 ns |       0 B |
 CaseSensitiveCultureInvariant | 1 |   217,116.7 ns |  2,212.376 ns |  1,961.213 ns |       0 B |
          SimplifiedExpression | 1 |     1,523.0 ns |     13.191 ns |     12.339 ns |       0 B |
      Case_Sensitive_Substring | 1 |       671.3 ns |      8.552 ns |      8.000 ns |       0 B |

Just in case you did not see here is the ETW chart:
grafik

Actually the Benchmark.NET numbers are even better. From the numbers it looks like the slow code gen path is only triggerd when RegexOptions.IgnoreCase is used. But anyway this is certainly a widely used option.