Skip to content

Conversation

@jasper-d
Copy link
Owner

The addition of Span<T> in .NET Core 2.1 can offer some performance
improvements moving through the array in SafeProxy by reducing the
number of arithmetic operations.

.NET Core 3.0 also adds Span<byte> based overloads to HashAlgorithm
which can further improve performance if explicitly supported. If not
supported, any requests to the Span<byte> overloads are copied to an
array before processing.

A BenchmarkDotNet project was also added to assist with benchmarking.

Test results across several target frameworks comparing the pre and post
change performance against a 65536 byte array. These metrics are for
calls in via the array overloads, not the Span<byte> overloads. They
show an approximately 25% reduction in runtime on .NET Core 2.1 and 3.1.

| Method |       Runtime |  Size |     Mean |    Error |   StdDev | Ratio | Rank |
|------- |-------------- |------ |---------:|---------:|---------:|------:|-----:|
|  Array |    .NET 4.6.1 | 65536 | 48.08 us | 0.192 us | 0.170 us |  1.00 |    1 |
|   Span |    .NET 4.6.1 | 65536 | 47.87 us | 0.169 us | 0.150 us |  1.00 |    1 |
|        |               |       |          |          |          |       |      |
|  Array | .NET Core 2.1 | 65536 | 48.99 us | 0.260 us | 0.217 us |  1.00 |    2 |
|   Span | .NET Core 2.1 | 65536 | 37.02 us | 0.261 us | 0.218 us |  0.76 |    1 |
|        |               |       |          |          |          |       |      |
|  Array | .NET Core 3.1 | 65536 | 50.01 us | 0.335 us | 0.297 us |  1.00 |    2 |
|   Span | .NET Core 3.1 | 65536 | 37.04 us | 0.218 us | 0.204 us |  0.74 |    1 |
@jasper-d jasper-d merged commit 670c561 into jasper-d:develop Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants