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
Microsoft.VisualBasic.Strings.InStr with CompareMethod.Text is 10x slower in .NET 7 than in .NET Framework 4.8 #88416
Comments
Tagging subscribers to this area: @cston Issue DetailsDescriptionMicrosoft.VisualBasic.Strings.InStr with CompareMethod.Text is 10x slower in .NET 7 than in .NET Framework 4.8. Full repro:
yields on my system:
csproj file:
Configuration
Regression?
|
I put your test into benchmarkdotnet, and I see the opposite, with .NET 7's throughput being 3x as fast as .NET Framework 4.8: using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Microsoft.VisualBasic;
BenchmarkSwitcher.FromAssembly(typeof(Tests).Assembly).Run(args);
public class Tests
{
[Benchmark]
public int Compare() => Strings.InStr("a", "b", CompareMethod.Text);
}
|
Even without BenchmarkDotNet, .NET 7.0 is still faster on my machine (AMD Ryzen 9 5950X).
When running the project in Rider and Debug mode (with debugger attached): .NET Framework 4.8: 898 And with BenchmarkDotNet (I've added .NET 8.0 as well):
|
This issue has been marked |
That's interesting. Using Stephen's BenchmarkDotNet code, I get the following results: .NET 7:
.NET Framework 4.8:
.NET 5: [Note the µs instead of ns]
Is there any additional information I can provide to find out what's different about my system? |
You're running in release, right? Or maybe the particular code paths used by this are causing an issue in the version of ICU used by the version of Windows 10 you're on? What do you get if you set the What's your default culture, i.e. if you output |
Yes, of course.
Bingo! Both NLS/ICU and the current culture are relevant. My default culture is de-AT.
Digging deeper into
I did a bit more reading on the NLS/ICU switch, and, apparently, worse performance for culture-aware string operations is a known issue. Thanks for all your help in getting to the root of this (and for introducing me to DotNetBenchmark). Since this is already known, I will close this issue. |
@tarekgh, is this expected? That's a huge gap based on which culture is used for the comparison (vs each other, not vs ordinal) |
@stephentoub there is an issue about the performance loss of switching to ICU: #40942 I also did see that Windows 10 uses an old version of ICU (#40942 (comment)), so I was curious if my installation also has the same results. My installation of Windows 11 22H2 uses 68.2.0.10.
So having a newer version of ICU sadly doesn't help. |
If you remember, we have added manual optimization code for |
Description
Microsoft.VisualBasic.Strings.InStr with CompareMethod.Text is 10x slower in .NET 7 than in .NET Framework 4.8.
Full repro:
yields on my system:
csproj file:
Configuration
Regression?
The text was updated successfully, but these errors were encountered: