Trim memory usage of IReadOnlyPackage implementations.

These implementations are often backed by a Dictionary, and tend to live a long time after being loaded. Ensure TrimExcess is called on the backing dictionaries to reduce the long term memory usage. In some cases, we can also preallocate the dictionary size for efficiency.
This commit is contained in:
RoosterDragon
2024-04-01 14:29:37 +01:00
committed by Gustas
parent ed5c7bb836
commit a4bb58007f
6 changed files with 23 additions and 11 deletions

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
public string Name { get; }
public IEnumerable<string> Contents => index.Keys;
readonly Dictionary<string, Entry> index = new();
readonly Dictionary<string, Entry> index;
readonly Stream s;
public BigFile(Stream s, string filename)
@@ -48,6 +48,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
// and we don't have to try seeking there since the entries typically start next in EA's .big files.
s.ReadUInt32();
index = new Dictionary<string, Entry>((int)entryCount);
for (var i = 0; i < entryCount; i++)
{
var entry = new Entry(s);