Skip to content

Add ContainsAny{Except} path to SearchValues - #96924

Merged
MihaZupan merged 1 commit into
dotnet:mainfrom
MihaZupan:searchvalues-containsany-2
Jan 19, 2024
Merged

Add ContainsAny{Except} path to SearchValues#96924
MihaZupan merged 1 commit into
dotnet:mainfrom
MihaZupan:searchvalues-containsany-2

Conversation

@MihaZupan

Copy link
Copy Markdown
Member

Followup after #87621 to add dedicated ContainsAny{Except} paths for SearchValues.
This PR adds such logic for SearchValues that go through IndexOfAnyAsciiSearcher.

I tried to avoid code duplication between IndexOfAny and ContainsAny by abusing generics some more. Don't know if that could lead to any downsides.

#96588 is renaming some files so if/after that is merged, we can wire up ContainsAny{Except} for single-value SearchValues to call into Contains helpers as well.

MethodToolchainMatchLengthMeanErrorRatio
ContainsAnymainFalse163.210 ns0.0605 ns1.00
ContainsAnyprFalse162.480 ns0.0098 ns0.78
ContainsAnyExceptmainFalse161.924 ns0.0134 ns1.00
ContainsAnyExceptprFalse162.008 ns0.0075 ns1.05
ContainsAnymainTrue164.332 ns0.0214 ns1.00
ContainsAnyprTrue161.857 ns0.0064 ns0.43
ContainsAnyExceptmainTrue162.512 ns0.0261 ns1.00
ContainsAnyExceptprTrue161.928 ns0.0085 ns0.77
Benchmark code
publicclassSearchValuesContainsAny{privatestaticreadonlySearchValues<char>s_values=SearchValues.Create("ABCDabcd1234");privatestring_text=null!;privatestring_textExcept=null!;[Params(false,true)]publicboolMatch;[Params(16)]publicintLength;[GlobalSetup]publicvoidSetup(){vartext=newstring('\n',Length).ToCharArray();vartextExcept=newstring('a',Length).ToCharArray();if(Match){text[0]='a';textExcept[0]='\n';}_text=newstring(text);_textExcept=newstring(textExcept);}[Benchmark]publicboolContainsAny()=>_text.AsSpan().ContainsAny(s_values);[Benchmark]publicboolContainsAnyExcept()=>_textExcept.AsSpan().ContainsAnyExcept(s_values);}

@MihaZupanMihaZupan added this to the 9.0.0 milestone Jan 12, 2024
@MihaZupanMihaZupan self-assigned this Jan 12, 2024
@ghost

Copy link
Copy Markdown

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

Issue Details

Followup after #87621 to add dedicated ContainsAny{Except} paths for SearchValues.
This PR adds such logic for SearchValues that go through IndexOfAnyAsciiSearcher.

I tried to avoid code duplication between IndexOfAny and ContainsAny by abusing generics some more. Don't know if that could lead to any downsides.

#96588 is renaming some files so if/after that is merged, we can wire up ContainsAny{Except} for single-value SearchValues to call into Contains helpers as well.

MethodToolchainMatchLengthMeanErrorRatio
ContainsAnymainFalse163.210 ns0.0605 ns1.00
ContainsAnyprFalse162.480 ns0.0098 ns0.78
ContainsAnyExceptmainFalse161.924 ns0.0134 ns1.00
ContainsAnyExceptprFalse162.008 ns0.0075 ns1.05
ContainsAnymainTrue164.332 ns0.0214 ns1.00
ContainsAnyprTrue161.857 ns0.0064 ns0.43
ContainsAnyExceptmainTrue162.512 ns0.0261 ns1.00
ContainsAnyExceptprTrue161.928 ns0.0085 ns0.77
Benchmark code
publicclassSearchValuesContainsAny{privatestaticreadonlySearchValues<char>s_values=SearchValues.Create("ABCDabcd1234");privatestring_text=null!;privatestring_textExcept=null!;[Params(false,true)]publicboolMatch;[Params(16)]publicintLength;[GlobalSetup]publicvoidSetup(){vartext=newstring('\n',Length).ToCharArray();vartextExcept=newstring('a',Length).ToCharArray();if(Match){text[0]='a';textExcept[0]='\n';}_text=newstring(text);_textExcept=newstring(textExcept);}[Benchmark]publicboolContainsAny()=>_text.AsSpan().ContainsAny(s_values);[Benchmark]publicboolContainsAnyExcept()=>_textExcept.AsSpan().ContainsAnyExcept(s_values);}
Author:MihaZupan
Assignees:MihaZupan
Labels:

area-System.Buffers

Milestone:9.0.0

@MihaZupan
MihaZupanforce-pushed the searchvalues-containsany-2 branch from c94005f to 7bccebeCompareJanuary 18, 2024 16:34
@MihaZupan
MihaZupan merged commit 2939fde into dotnet:mainJan 19, 2024
tmds pushed a commit to tmds/runtime that referenced this pull request Jan 23, 2024
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Feb 18, 2024
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