Avoid some allocations on the large object heap during loading.

- In MixFile, the Distinct call doesn't presize the HashSet it uses internally. As we know we will enumerate all results, create the HashSet ourselves so that is it presized correctly.
- In ObjectCreator, stream the assembly when hashing rather than reading all bytes into memory.

These changes avoid some allocations on the large object heap, in turn this means the GC can avoid performing unnecessary Gen 2 collections just to clear down the LOH.
This commit is contained in:
RoosterDragon
2023-07-02 16:35:45 +01:00
committed by abcdefg30
parent 659ec5e335
commit be04d232c0
2 changed files with 8 additions and 5 deletions

View File

@@ -55,7 +55,9 @@ namespace OpenRA
// (a) loading duplicate data into the application domain, breaking the world.
// (b) crashing if the assembly has already been loaded.
// We can't check the internal name of the assembly, so we'll work off the data instead
var hash = CryptoUtil.SHA1Hash(File.ReadAllBytes(resolvedPath));
string hash;
using (var stream = File.OpenRead(resolvedPath))
hash = CryptoUtil.SHA1Hash(stream);
if (!ResolvedAssemblies.TryGetValue(hash, out var assembly))
{