From 19dc4a141cae8f09415c8766ef5b450d78390381 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Sun, 7 Dec 2025 19:10:04 +0100 Subject: [PATCH] LogMessage GetProperties without FrozenDictionary --- src/core/Akka/Event/LogMessage.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/Akka/Event/LogMessage.cs b/src/core/Akka/Event/LogMessage.cs index ba2531af548..229e63e1108 100644 --- a/src/core/Akka/Event/LogMessage.cs +++ b/src/core/Akka/Event/LogMessage.cs @@ -79,7 +79,15 @@ public IReadOnlyDictionary GetProperties() // Optimize: avoid ToArray() if Parameters() already returns IReadOnlyList if (parameters is IReadOnlyList readOnlyList) { - _properties = CreatePropertyDictionary(PropertyNames, readOnlyList); + if (readOnlyList.Count == 0) + { + // Optimize: Skips parsing PropertyNames when empty Parameters() + _properties = EmptyDictionary; + } + else + { + _properties = CreatePropertyDictionary(PropertyNames, readOnlyList); + } } else { @@ -109,12 +117,7 @@ private static IReadOnlyDictionary CreatePropertyDictionary( dict[names[i]] = values[i]; } -#if NET8_0_OR_GREATER - // Use FrozenDictionary for optimal read performance on .NET 8+ - return System.Collections.Frozen.FrozenDictionary.ToFrozenDictionary(dict); -#else return dict; -#endif } private static readonly IReadOnlyDictionary EmptyDictionary =