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

Use vectorized SpanHelpers.SequenceEqual for string equality #16994

Merged
merged 1 commit into from Mar 17, 2018

Conversation

Projects
None yet
3 participants
@jkotas
Member

jkotas commented Mar 16, 2018

SpanHelpers.SequenceEqual is our optimized workhorse for comparing blocks of memory. Use it for string equality instead of ad-hoc optimized loops.

"Hello world!".Equals("Hello world?") is 20% faster on x64 with this change and it only gets better from there.

@jkotas jkotas requested a review from ahsonkhan Mar 16, 2018

@jkotas

This comment has been minimized.

Member

jkotas commented Mar 16, 2018

Depends on dotnet/corefx#28080 that is changing SpanHelpers.SequenceEqual argument to nuint.

@jkotas

This comment has been minimized.

Member

jkotas commented Mar 16, 2018

@@ -1126,7 +1018,10 @@ public Boolean StartsWith(String value, StringComparison comparisonType)
}
return (value.Length == 1) ?
true : // First char is the same and thats all there is to compare
StartsWithOrdinalHelper(this, value);
SpanHelpers.SequenceEqual(

This comment has been minimized.

@ahsonkhan

ahsonkhan Mar 16, 2018

Member

What happens if this.Length is less than value.Length?

This comment has been minimized.

@jkotas

jkotas Mar 16, 2018

Member

This condition is checked two lines above this one.

@ahsonkhan

lgtm

@marek-safar

This comment has been minimized.

Contributor

marek-safar commented Mar 16, 2018

@jkotas very nice

We are still using https://github.com/dotnet/corert/blob/master/src/System.Private.CoreLib/src/System/String.Comparison.cs but this file looks quite easy to unify/share

@jkotas

This comment has been minimized.

Member

jkotas commented Mar 17, 2018

@dotnet-bot test this please

@jkotas

This comment has been minimized.

Member

jkotas commented Mar 17, 2018

@dotnet-bot test Ubuntu x64 Checked corefx_baseline
@dotnet-bot test Windows_NT x64 Checked corefx_baseline

@jkotas jkotas merged commit f8228fe into dotnet:master Mar 17, 2018

17 of 20 checks passed

Ubuntu x64 Checked Build and Test (Jit - CoreFx) Build finished.
Details
Windows_NT arm64 Cross Checked Innerloop Build and Test Build finished.
Details
Windows_NT armlb Cross Checked Innerloop Build and Test Build finished.
Details
Alpine.3.6 x64 Debug Build Build finished.
Details
CROSS Check Build finished.
Details
CentOS7.1 x64 Checked Innerloop Build and Test Build finished.
Details
CentOS7.1 x64 Debug Innerloop Build Build finished.
Details
OSX10.12 x64 Checked Innerloop Build and Test Build finished.
Details
Tizen armel Cross Checked Innerloop Build and Test Build finished.
Details
Ubuntu arm64 Cross Debug Innerloop Build Build finished.
Details
Ubuntu x64 Checked Innerloop Build and Test Build finished.
Details
Ubuntu x64 Formatting Build finished.
Details
WIP ready for review
Details
Windows_NT arm Cross Checked Innerloop Build and Test Build finished.
Details
Windows_NT x64 Checked Build and Test (Jit - CoreFx) Build finished.
Details
Windows_NT x64 Checked Innerloop Build and Test Build finished.
Details
Windows_NT x64 Formatting Build finished.
Details
Windows_NT x86 Checked Innerloop Build and Test Build finished.
Details
Windows_NT x86 Release Innerloop Build and Test Build finished.
Details
license/cla All CLA requirements met.
Details

@jkotas jkotas deleted the jkotas:spanhelpers-string branch Mar 19, 2018

@dotnet dotnet deleted a comment Nov 7, 2018

@dotnet dotnet deleted a comment from ahsonkhan Nov 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment