Immutable Collections in NET: Why and How?
summary
Argues that replacing shared mutable state with persistent structures simplifies threading, cuts implicit context and cancels, and preserves correctness using compare-and-swap loops and ImmutableInterlocked helpers. Dives into System.Collections.Immutable implementations (copy-on-write arrays, linked-list stacks, two-stack queues, rope-like immutable lists) and microbenchmarks: inserting in the middle stays fast up to 100,000 elements for immutable lists while mutable List degrades around 10k–100k, and an immutable sorted dictionary is ~2x faster than the hash-based immutable version. Notes higher GC/memory pressure.
AI-written summary · about
chapters (6)
- 0:00Start
- 1:16Code quality maintenance
- 6:41Introduction to immutable collections
- 7:42Motivation - Why? Where can you apply immutable collections?
- 28:12Review well-known immutable objects
- 47:14Inspect internal structure and performance
related talks
47mUsing Immutable Data Structures in C# and .NET
50mImmutable code in .NET
48mUsing Immutable Data Structures in C# and .NET
38mImmutability is everything!
59mWriting (in)efficient C#
37mThe Mutability Matrix of Pain: An Accessible Exploration of the JVM Heap
01h 04mOur favorite things in .NET 8
40mImmutable Data Structures in C++
