Use `StringPool` from CommunityToolkit in `ToUpperASCIIFast` extension

from be0736be4 (+ cherry-picked ccba93440) to this commit:
- `Database` reported runtime 0.64 s --> 0.68 s
- profiled `ParseCGIRecord` mean runtime 0.190 ms --> 0.179 ms
- `GameDBHelper` 1M lookups reported runtime 1.03 s --> 0.69 s
- managed allocations (w/o the 1M lookups) 131 MiB --> 123 MiB (fewer
strings but more char[]s?)

since `CompactGameInfo` obviously can't store `Span`s, I tried with
`StringSegment`, but it made both lookups *and init* slower, thanks MS
This commit is contained in:
YoshiRulz 2024-12-16 23:13:34 +10:00
parent c2200cb234
commit 3095aca86a
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 5 additions and 1 deletions

View File

@ -1,5 +1,6 @@
<Project>
<ItemGroup>
<PackageVersion Include="CommunityToolkit.HighPerformance" Version="8.3.2" />
<PackageVersion Include="Cyotek.Drawing.BitmapFont" Version="2.0.4" />
<PackageVersion Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.59" />
<PackageVersion Include="Google.FlatBuffers" Version="23.5.26" /> <!-- last version with .NET Standard 2.0 support -->

View File

@ -8,6 +8,7 @@
<PolySharpUsePublicAccessibilityForGeneratedTypes>true</PolySharpUsePublicAccessibilityForGeneratedTypes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.HighPerformance" />
<PackageReference Include="Microsoft.Bcl.HashCode" />
<PackageReference Include="Microsoft.Win32.Registry" />
<PackageReference Include="PolySharp" />

View File

@ -1,6 +1,8 @@
using System.Linq;
using System.Runtime.CompilerServices;
using CommunityToolkit.HighPerformance.Buffers;
namespace BizHawk.Common.StringExtensions
{
public static class StringExtensions
@ -199,7 +201,7 @@ namespace BizHawk.Common.StringExtensions
var c = str[i];
a[i] = c is >= 'a' and <= 'z' ? unchecked((char) (c & ASCII_UPCASE_MASK)) : c;
}
return new(a);
return StringPool.Shared.GetOrAdd(a);
}
return str;
}