From 5012c093687c629ffdf26918ed712c8469c824eb Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sat, 9 Apr 2022 20:17:07 +0200 Subject: [PATCH] Optimize GetMD5 function | Method | Mean | Error | StdDev | Gen 0 | Allocated | |----------------------------- |---------:|--------:|--------:|-------:|----------:| | Old | 795.1 ns | 5.90 ns | 4.61 ns | 0.0029 | 312 B | | HashDataInsteadOfComputeHash | 396.1 ns | 1.36 ns | 1.13 ns | 0.0014 | 152 B | | StackallocedDestination | 395.8 ns | 1.80 ns | 1.60 ns | 0.0014 | 152 B | | RentBuffer | 498.8 ns | 3.35 ns | 2.97 ns | - | 40 B | Tested multiple possible speedups, in the end the simplest of them all won --- MediaBrowser.Common/Extensions/BaseExtensions.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/MediaBrowser.Common/Extensions/BaseExtensions.cs b/MediaBrowser.Common/Extensions/BaseExtensions.cs index 08964420e7..e3775021e1 100644 --- a/MediaBrowser.Common/Extensions/BaseExtensions.cs +++ b/MediaBrowser.Common/Extensions/BaseExtensions.cs @@ -31,11 +31,7 @@ namespace MediaBrowser.Common.Extensions public static Guid GetMD5(this string str) { #pragma warning disable CA5351 - using (var provider = MD5.Create()) - { - return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str))); - } - + return new Guid(MD5.HashData(Encoding.Unicode.GetBytes(str))); #pragma warning restore CA5351 } }