-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImmutableList inconsistency with List #110081
Comments
Tagging subscribers to this area: @dotnet/area-system-collections |
It's a tree.
https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-8/#frozen-collections provides background about what the immutable collections are and why they perform the way they do.
How would that differ from |
I corrected the description.
It would not expose any mutation methods for consistency with |
The purpose of the “frozen” collections is to trade off extra computation time during creation in exchange for much faster reads, similar to As for why it’s a tree structure, you have to consider its purpose: it’s an immutable list. That means every modification needs to return a whole new allocation. To reduce how much allocation is required, using segments (which traversing a tree can accomplish) allows only allocating the segments the insertion point requires (which is |
The logic behind the Immutable and Frozen collections is well understood by our team. This issue is meant to highlight the inconsistency in the naming of the classes:
The above leads to human error. We also never use the mutating methods of the immutable collections. While not reported in my original post, as is it is now we have to use Let's say you accidentally added a So in practical terms we would prefer a set of |
An alternative would be to add a new set of collections with a different naming convention, let's say That however would introduce yet another set of classes and so adding the missing |
I don't think it's reasonable to assume that the term "List" necessarily implies a buffer backed implementation. This would be similar to assuming that As already mentioned, |
Why sunset the type? It's invaluable. It's an immutable sequence of elements that can be used to create new immutable sequences much more efficiently than what is possible with types like ImmutableArray. The different types have different characteristics and different intended use cases. The cases for ImmutableList are quite sound and are needed and appropriate in many domains. |
.... Although I think people are missing something really trivial here; The implication of the OP's needs is that people are passing in whatever collection into something accepting a concrete type. Who cares what the actual backing type is, only hand out the behavior reference. |
ImmutableList
is implemented as a tree which is confusing. Judging by its name, the user of this class likely expects performance characteristics similar to aList
. Anecdotally we regularly find instances in our project's code where someone unintentionally used anImmutableList
instead of anImmutableArray
.The proposed solution is to add a
FrozenList
class, complementing the existingFrozenDictionary
andFrozenSet
classes, backed by an array and with the same computational complexity asList
.In addition to the above consider renaming
ImmutableList
toImmutableTreeList
but that would break backward compatibility.The text was updated successfully, but these errors were encountered: