-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
New SearchValues<string> API doesn't use vectorized equality comparison once it finds a candidate #96142
Comments
Tagging subscribers to this area: @dotnet/area-system-buffers Issue DetailsProblemThe new This is a missed opportunity as Vectorized equality would be perfect here, especially considering the implementations of It would be unfortunate if basic uses of this API are actually slower compared to Benchmark CodeConsider the following benchmark code run in my local copy of dotnet/performance. It's an extreme example designed to prove the point - discussion later.
Benchmark Results
AnalysisIt's clear that the new SearchValues API is slower than we would like in the above cases. This is because it's optimized to find the first candidate character position which in the benchmark is index I also couldn't find any benchmarks of this API in dotnet/performance, so maybe I've done something wrong. Please note I'm not trying to bash this amazing API, just to point out where I saw a possible improvement. The strategy selection and reading about Teddy was truly inspiring.
|
Thanks for raising the issue. But I agree a vectorized verification does make a lot of sense for scenarios like yours. |
Problem
The new
SearchValues<string>
has incredible strategies to find candidates where it suspects there might be a match but once it finds a match, uses a simple loop to confirm. Specifically implementations of StringSearchValuesHelper.ICaseSensitivity useScalarEquals
which is a for loop comparingchar
s.This is a missed opportunity as Vectorized equality would be perfect here, especially considering the implementations of
ICaseSensitivity
already are able to transform vectors with some clever optimizations of their own.It would be unfortunate if basic uses of this API are actually slower compared to
string.IndexOf(string)
in certain cases.Benchmark Code
Consider the following benchmark code run in my local copy of dotnet/performance. It's an extreme example designed to prove the point - discussion later.
Benchmark Results
Analysis
It's clear that the new SearchValues API is slower than we would like in the above cases. This is because it's optimized to find the first candidate character position which in the benchmark is index
0
which negates the benefit. Thus the remainder of the work is verifying the candidate at the position, which I would guess is vectorized in thestring.IndexOf
/string.Equal
approaches.I also couldn't find any benchmarks of this API in dotnet/performance, so maybe I've done something wrong.
Please note I'm not trying to bash this amazing API, just to point out where I saw a possible improvement. The strategy selection and reading about Teddy was truly inspiring.
The text was updated successfully, but these errors were encountered: