.NET 8 FrozenDictionary benchmarks

For those that don’t know Microsoft have introduced new FrozenDictionary and FrozenSet collections in .NET 8 (from Preview 1).

These collections will reside in the System.Collections.Frozen namespace and are collections which are performance optimized for READ ONLY scenarios.

Just for fun I ran some benchmarks (code below) to compare the performance of a FrozenDictionary against other existing types of dictionaries and the times ⌚ are below 👇🏻 …

Click on the image for a larger view in a new window …

We can see from above that time to create READ OPTIMIZED FrozenDictionarys is HUGE compared to alternatives BUT the trade off is faster reads. Remember, these new collections are intended for long-lived state used repeatedly in the life of a service.

Why use collections in the new System.Collections.Frozen namespace in .NET 8 versus the existing ones in System.Collections.Immutable?

Good clarity on the differences between Frozen and Immutable collections from Stephen Toub on the MS devblogs site earlier this year 👇🏻 …

Click on the image for a larger view in a new window …

A great addition to .NET I think.
What do you think?
Have you a use case for these new frozen collections?

Benchmark Code

If anyone uses BenchmarkDotNet and want’s to try and recreate the benchmarks the code is here -> FrozenDictionary in .NET 8 benchmarks compared to Dictionary/ReadOnlyDictionary etc. (github.com)

One thought on “.NET 8 FrozenDictionary benchmarks”

  1. Ok the benchmarks you post completely confuse me. According to them, ImmutableDictionary is significantly slower than a regular Dictionary. Like twice as slow.

    What then, is the point of Immutable Dictionary. I would expect that something immutable would be faster to access. Why would anyone want to use an ImmutableDictionary, given those benchmarks?

Leave a Reply

Your email address will not be published. Required fields are marked *