-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Investigate ways to optimize Span.Fill and Span.Clear for small buffers #24806
Comments
We should look at |
I know this issue specifically deals with small buffers, but do we know the calling patterns for how these APIs are likely to be used? For example, is it likely that |
I think it going to be most frequently used with spans of primitive types (byte, char, int), but it needs to work for all types. |
I investigated One alternative is to expose a specialty API |
Where is the regression for larger buffers coming from? |
There is always step or bend in the performance curve where implementation switches to a different strategy. It should get amortized for larger buffers pretty quickly. |
@jkotas Currently When I was experimenting with optimizing for small buffers the code looked like the following. private static void ClearWithoutReferences(/* ... */) {
if (length > 4096) { goto PInvoke; }
else if (length > 16) { goto JIT_Memset; }
else {
/* optimize for small cases */
}
} The modified I should note that the microbenchmark was using a fully primed branch predictor. |
We need to reduce the overhead of calling Span and ReadOnlySpan Fill and improve its performance for small buffers so that it can be used in common scenarios.
See additional context:
dotnet/corefx#26598 (comment)
dotnet/corefx#26289 (comment)
Edit: As part of this change, investigate and remove the TODOs:
https://github.com/dotnet/corefx/blob/79d708b2faf8a75089b1873fbb101b0a957c1fbd/src/System.Memory/src/System/SpanHelpers.Clear.cs#L69
https://github.com/dotnet/corefx/blob/79d708b2faf8a75089b1873fbb101b0a957c1fbd/src/System.Memory/src/System/SpanHelpers.Clear.cs#L105
https://github.com/dotnet/coreclr/blob/22f1bc00d018a49f9550ee3b564f5f7737960b0d/src/mscorlib/shared/System/Span.NonGeneric.cs#L707
cc @dotnet/corefxlab-contrib, @jkotas, @stephentoub
The text was updated successfully, but these errors were encountered: