Frozen collections in .NET 8 #27
Replies: 12 comments 24 replies
-
|
Why have they created only FrozenSet and not FrozenList for example? Comparing the performance of List and FrozenSet seems unfair, you should compare HashSet and FrozenSet no? Please let me know what detail I am missing. |
Beta Was this translation helpful? Give feedback.
-
|
I agree that the benchmark unfortunately doesn't look too meaningful. Lists aren't exactly designed for lookups/contains operations and do so in O(N), sets are generally designed to be faster (often O(1)). A fair comparison would probably be a classic HashSet, as well as maybe an ImmutableSet compared against a frozen set. It'd also be quite interesting to explore how the frozen state is achieved, as that almost certainly has some performance overhead at some point too. Eg does it just create a defensive copy of the underlying data (which might mean construcition is O(N)'ish, vs. O(1) of just wrapping a set into some IReadOnlySet)? Can it do anything smarter than that? |
Beta Was this translation helpful? Give feedback.
-
|
Meaningless benchmarks. |
Beta Was this translation helpful? Give feedback.
-
|
In order to make the post more accurate, the transformation to each of the subtypes (frozen, immutable and hash) should also have benchmarks, since the guy that developed it said it would take longer to setup the immutable set |
Beta Was this translation helpful? Give feedback.
-
|
Is this implemented only in C# or is it part of MSIL? Most of the C# languages tricks/shortcuts, when viewed in MSIL, are not really an improvement. |
Beta Was this translation helpful? Give feedback.
-
|
private const int OneHundred = 100; Why....? |
Beta Was this translation helpful? Give feedback.
-
|
Would help a lot if you did not use the |
Beta Was this translation helpful? Give feedback.
-
|
Your two hashset definitions seem to be exactly the same. Also, discarding result variables can lead to dead code optimizations that can greatly skew the results. A more ideal approach would be for example using that result to increment a field. |
Beta Was this translation helpful? Give feedback.
-
|
The ReadOnlyList in your implementation is, like you put it, only a view to a reference.
I can't speak for the performance though. |
Beta Was this translation helpful? Give feedback.
-
|
The reason why there isn't a FrozenList is that ImmutableArray already serves the same role. Whereas the other ImmutableXXX types are designed to provide reasonably efficient way to create modified clones of themselves, ImmutableArray is not and works in fact like the FrozenXXX collections. Unfortunately, renaming ImmutableArray to FrozenList would be a breaking change, so we'll have to live with the name as-is. |
Beta Was this translation helpful? Give feedback.
-
|
@linkdotnet ImmutableSet and ImmutableDictionary are designed to be immutable and to make it easy to create slightly modified copies of a given instance at a reasonable cost. So imagine you create an immutable set with a million entries in it. You cannot mutate this set since it is immutable. Now, you need a new set with 1 extra entry. You could recreate the set from the ground up, which would be very expensive. Instead, you can start from your original immutable set and apply a delta to create a new distinct set instance which under the covers shares most of the state from the original set. You use less memory this way, and it takes much less time to create the new instance. The problem is that in order to allow this mode of operation, ImmutableDictionary and ImmutableSet are complex implementations which introduce substantial compromises in overall read performance as a trade-off for this ability to make cheap delta clones. FrozenSet and FrozenDictionary do not provide the delta clone ability, they are optimized strictly for fast read performance. You pay more for creation, you pay more for making a clone with modifications, as a trade-off for getting faster steady state read performance. |
Beta Was this translation helpful? Give feedback.
-
|
Does anybody know if these new Frozen collections will be thread safe to read? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Frozen collections in .NET 8
.NET 7 was freshly released but Microsoft does not sleep. .NET 8 is already in the making and I want to showcase to you one new area where the dotnet team is working on Frozen collections.
So let's have a look at what frozen collections are and how they are working.
https://steven-giesel.com/blogPost/34e0fd95-0b3f-40f2-ba2a-36d1d4eb5601
Beta Was this translation helpful? Give feedback.
All reactions