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