Skip to content
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

Improve SpanHelpers.IndexOfAny(byte,byte) #40747

Conversation

benaadams
Copy link
Member

@benaadams benaadams commented Aug 13, 2020

The better approached used in #40729

| Faster                                                   | base/diff | Base Median (ns) | Diff Median (ns) | Modality|
| -------------------------------------------------------- | ---------:| ----------------:| ----------------:| --------:|
| System.Memory.Span<Byte>.IndexOfAnyTwoValues(Size: 16)   |      1.45 |             5.02 |             3.45 |         |
| System.Memory.Span<Byte>.IndexOfAnyTwoValues(Size: 24)   |      1.52 |             5.93 |             3.91 |         |
| System.Memory.Span<Byte>.IndexOfAnyTwoValues(Size: 32)   |      1.44 |             6.09 |             4.23 |         |
| System.Memory.Span<Byte>.IndexOfAnyTwoValues(Size: 48)   |      1.69 |             5.82 |             3.45 |         |
| System.Memory.Span<Byte>.IndexOfAnyTwoValues(Size: 64)   |      1.40 |             5.82 |             4.17 |         |
| System.Memory.Span<Byte>.IndexOfAnyTwoValues(Size: 128)  |      1.29 |             6.36 |             4.94 |         |
| System.Memory.Span<Byte>.IndexOfAnyTwoValues(Size: 512)  |      1.43 |            10.75 |             7.54 |         |
| System.Memory.Span<Byte>.IndexOfAnyTwoValues(Size: 256)  |      1.34 |             7.58 |             5.67 |         |
| System.Memory.Span<Byte>.IndexOfAnyTwoValues(Size: 1024) |      1.11 |            12.99 |            11.69 |         |

Will effect header parsing in Kestrel

length = span.IndexOfAny(ByteCR, ByteLF)

/cc @adamsitnik @danmosemsft

@benaadams benaadams force-pushed the Improve-SpanHelpers.IndexOfAny(byte,byte)- branch from f7652c5 to 6e7f28e Compare August 13, 2020 03:41
@benaadams benaadams marked this pull request as ready for review August 13, 2020 04:33
Copy link
Member

@gfoidl gfoidl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

…te.cs

Co-authored-by: Günther Foidl <gue@korporal.at>
…te.cs

Co-authored-by: Dan Moseley <danmose@microsoft.com>
@danmoseley
Copy link
Member

@benaadams @sebastienros is there a way to quantify how much it would help Kestrel? Would help prioritize review.

@benaadams
Copy link
Member Author

Top one of the SpanHelpers for PlainText Platform on Citrine on Linux

image

Not sure how it changes it though :)

@adamsitnik adamsitnik added the tenet-performance Performance related issue label Aug 14, 2020
@adamsitnik adamsitnik added this to the 5.0.0 milestone Aug 14, 2020
lengthToExamine = ((nuint)(uint)length - offset);
goto SequentialScan;
}
if (!TryFindFirstMatchedLane(mask, matches, ref matchedLane))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this for ARM as well.

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for doing this.

Comment on lines +609 to +613
// >= Sse2 intrinsics are supported, and length is enough to use them so use that path.
// We jump forward to the intrinsics at the end of the method so a naive branch predict
// will choose the non-intrinsic path so short lengths which don't gain anything aren't
// overly disadvantaged by having to jump over a lot of code. Whereas the longer lengths
// more than make this back from the intrinsics.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful comment; thank you.

@kunalspathak kunalspathak merged commit b932a51 into dotnet:master Aug 14, 2020
@benaadams benaadams deleted the Improve-SpanHelpers.IndexOfAny(byte,byte)- branch August 14, 2020 17:45
@danmoseley
Copy link
Member

@sebastienros do you expect this to materially improve Plaintext, given data above?

@sebastienros
Copy link
Member

We can hope it doesn't make it slower! Ideally any perf related work should be measured before merged, even more that close to rc. We'll have to look at the charts once the build is available. We can also do a custom with the next build containing this change. I'll follow the CI.

@jeffhandley
Copy link
Member

I recommended to @kunalspathak that we go ahead and merge, but good point, @sebastienros. Thanks for checking on it.

@adamsitnik
Copy link
Member

@benaadams thank you for another great improvement!

@kunalspathak big thanks for reviewing and merging the PR!

:shipit:

@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants