Skip to content

Use IndexOfAnyValues in CoreLib - #78678

Merged
MihaZupan merged 2 commits into
dotnet:mainfrom
MihaZupan:indexofanyvalues-corelib-1
Nov 22, 2022
Merged

Use IndexOfAnyValues in CoreLib#78678
MihaZupan merged 2 commits into
dotnet:mainfrom
MihaZupan:indexofanyvalues-corelib-1

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

Contributes to #78204

Avoids the cost of initializing the ProbabilisticMap on every matched value for ReplaceLineEndings.

MethodToolchainInputMeanErrorRatio
ReplaceLineEndingsmain\n\n(...)\n\n [1000]26,379.96 ns142.148 ns1.00
ReplaceLineEndingspr\n\n(...)\n\n [1000]13,946.75 ns49.276 ns0.53
ReplaceLineEndingsmainaaaaa(...)aaaaa [32]46.70 ns0.179 ns1.00
ReplaceLineEndingspraaaaa(...)aaaaa [32]33.29 ns0.356 ns0.71

In this case we're using "\r\n\f\u0085\u2028\u2029" as the needle.
We also have a bunch of uses of char.IsWhiteSpace where the needle likewise contains both ASCII and non-ASCII chars.

As ASCII values are more common in these cases, we could consider adding IndexOfAnyValues implementations with loops like this in the future:

while(remaining>vector256){varvector=Vector256.LoadUnsafe(...);if(AllCharsAreAscii(vector)){IndexOfAnyAsciiSearcher.Lookup(vector,_bitmap);}else{// Fallback to ProbabilisticMap or even IndexOfAny(char, char, char)}}

@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

Contributes to #78204

Avoids the cost of initializing the ProbabilisticMap on every matched value for ReplaceLineEndings.

MethodToolchainInputMeanErrorRatio
ReplaceLineEndingsmain\n\n(...)\n\n [1000]26,379.96 ns142.148 ns1.00
ReplaceLineEndingspr\n\n(...)\n\n [1000]13,946.75 ns49.276 ns0.53
ReplaceLineEndingsmainaaaaa(...)aaaaa [32]46.70 ns0.179 ns1.00
ReplaceLineEndingspraaaaa(...)aaaaa [32]33.29 ns0.356 ns0.71

In this case we're using "\r\n\f\u0085\u2028\u2029" as the needle.
We also have a bunch of uses of char.IsWhiteSpace where the needle likewise contains both ASCII and non-ASCII chars.

As ASCII values are more common in these cases, we could consider adding IndexOfAnyValues implementations with loops like this in the future:

while(remaining>vector256){varvector=Vector256.LoadUnsafe(...);if(AllCharsAreAscii(vector)){IndexOfAnyAsciiSearcher.Lookup(vector,_bitmap);}else{// Fallback to ProbabilisticMap or even IndexOfAny(char, char, char)}}
Author:MihaZupan
Assignees:-
Labels:

area-System.Runtime

Milestone:8.0.0

@MihaZupan

Copy link
Copy Markdown
MemberAuthor

The checked arm64 failures are #78718

@MihaZupan
MihaZupan merged commit 47158cc into dotnet:mainNov 22, 2022
@ghostghost locked as resolved and limited conversation to collaborators Dec 23, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@MihaZupan@stephentoub