Writing · 21.03.26 · 1 min

FrozenDictionary: when does it pay off?

Real benchmarks on read-heavy hot paths. Does ConcurrentDictionary still win?

FrozenDictionary: when does it pay off?

.NET 8's FrozenDictionary helps in read-heavy, write-rare scenarios — not for every dictionary swap. In my bench with 100k keys and 99% reads, lookups improved roughly 15-20%. With frequent insert/update, ConcurrentDictionary still wins — frozen structures penalize writes.

When I use it: config maps, lookup tables, enum → string mappings filled at startup then frozen. Not for request-scope cache or session state.

FrozenDictionary vs ConcurrentDictionary

var map = configs.ToFrozenDictionary(c => c.Key, c => c.Value);

Profile the hot path. A measured decision, not a micro-optimization trophy. "Faster" on a slide isn't enough.

FrozenDictionary: when does it pay off? — Aziz Osmanoğlu