From 62502d4db13dcdd5b863583e0bf2d51720897fbe Mon Sep 17 00:00:00 2001 From: zingballyhoo Date: Mon, 18 Nov 2024 23:42:09 +0000 Subject: [PATCH] ConcurrentDictionary and ToFrozenDictionary are not friends --- TACTLib/Protocol/CDNIndexHandler.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/TACTLib/Protocol/CDNIndexHandler.cs b/TACTLib/Protocol/CDNIndexHandler.cs index 0cfe334..f81356a 100644 --- a/TACTLib/Protocol/CDNIndexHandler.cs +++ b/TACTLib/Protocol/CDNIndexHandler.cs @@ -99,9 +99,16 @@ private CDNIndexHandler(ClientHandler client) // converting to a frozen dictionary afterwards helps a bit but the arrays are still wasteful // also means the peak memory is higher during conversion // using IDictionary is also worse for lookup perf, but this keeps the code simpler for now - CDNIndexData = CDNIndexData.ToFrozenDictionary(CASCKeyComparer.Instance); // we could load each index into an array of entries and then merge sort into one giant array... // (also means higher building memory cost but maybe that's inevitable) + + if (!client.CreateArgs.ParallelCDNIndexLoading) + { + // ToFrozenDictionary doesn't like ConcurrentDictionary + // before processing it internally converts it to a normal Dictionary + // for a dictionary with 9 million entries, this is a perf disaster + CDNIndexData = CDNIndexData.ToFrozenDictionary(CASCKeyComparer.Instance); + } } private bool LoadGroupIndexFile(string hash) {