Open teo-tsirpanis opened 4 months ago
Definitely are areas if performance improvements now that we are moving up the minimum .NET version. Do you know if the System.IO.Hashing is any faster then the one the SDK uses?
MD5 is challenging for .NET Framework in a FIPS environment. Like you said we added it 9 years ago because you can't instantiate the MD5 objects in .NET Framework in a FIPS environment. We are not abandoning .NET Framework as part of V4 so don't see us switching away.
I ran some benchmarks for the CRC algorithms. For CRC32 the System.IO.Hashing
implementation is significantly faster than aws-c-checksums
on all tested sizes (16 bytes, 1KiB, 1Mib, 64Mib). System.IO.Hashing
does not provide a CRC32C implementation but I wrote one with the help of the BitOperations.Crc32C
method (introduced in .NET 8, will have to be polyfilled for earlier frameworks) and it was faster on small buffers and up to 6% slower on larger ones.
The system's MD5 implementation becomes increasingly faster on larger buffer sizes. Considering the FIPS implications, we could try using it first, and add fall back to the managed implementation if it throws.
BenchmarkDotNet v0.14.0, Windows 10 (10.0.19045.4842/22H2/2022Update)
Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK 8.0.400
[Host] : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.8 (8.0.824.36612), X64 RyuJIT AVX2
Method | Size | Mean | Error | StdDev | Median | Ratio | RatioSD |
---|---|---|---|---|---|---|---|
Md5System | 16 | 425.6 ns | 8.59 ns | 17.74 ns | 418.2 ns | 0.98 | 0.04 |
Md5Managed | 16 | 433.6 ns | 5.85 ns | 5.48 ns | 432.6 ns | 1.00 | 0.02 |
Md5System | 1024 | 2,923.9 ns | 58.19 ns | 67.02 ns | 2,935.5 ns | 0.62 | 0.02 |
Md5Managed | 1024 | 4,697.4 ns | 91.26 ns | 127.93 ns | 4,677.5 ns | 1.00 | 0.04 |
Md5System | 1048576 | 2,546,400.4 ns | 49,584.99 ns | 50,920.13 ns | 2,531,915.2 ns | 0.61 | 0.02 |
Md5Managed | 1048576 | 4,152,450.3 ns | 78,730.29 ns | 73,644.36 ns | 4,173,361.3 ns | 1.00 | 0.02 |
Md5System | 67108864 | 163,596,564.7 ns | 3,253,729.37 ns | 3,341,340.51 ns | 162,646,375.0 ns | 0.58 | 0.01 |
Md5Managed | 67108864 | 284,266,263.3 ns | 5,055,510.86 ns | 4,728,928.00 ns | 284,251,250.0 ns | 1.00 | 0.02 |
Describe the feature
I read the code in the
CryptoUtil.cs
file and noticed that there are some things that could be improved.Use Case
Cleaning-up the codebase and improving maintainability.
Proposed Solution
System.IO.Hashing
to implement CRC hashing.AWSSDK.Extensions.System.IO.Hashing
package that provides an alternative implementation.CryptoUtil
could even be removed from the public API but that would be a needless breaking change.Other Information
No response
Acknowledgements
AWS .NET SDK and/or Package version used
v4
Targeted .NET Platform
All
Operating System and version
All