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:
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user