✨ Implement ImmutableSegmentedHashSet<T>#54719
Conversation
These types are copied from dotnet/runtime@v5.0.8.
a3df5bf to
0ca55e6
Compare
|
@dotnet/roslyn-compiler this is now ready for review |
| } | ||
| else | ||
| { | ||
| // TODO: Avoid the builder allocation |
There was a problem hiding this comment.
Are these todo's from the original source?
There was a problem hiding this comment.
No, these are ways the current implementation could theoretically be improved. My hope is that if someone sees allocations of certain types in the future, they are directed to the most straightforward way to eliminate those allocations.
There was a problem hiding this comment.
Here's an example of how I broke out a ValueBuilder nested type to reduce builder allocations in ImmutableSegmentedList<T>:
#54424
https://github.com/dotnet/roslyn/blob/main/src/Dependencies/Collections/ImmutableSegmentedList%601%2BValueBuilder.cs
|
@dotnet/roslyn-compiler for second review |
4 similar comments
|
@dotnet/roslyn-compiler for second review |
|
@dotnet/roslyn-compiler for second review |
|
@dotnet/roslyn-compiler for second review |
|
@dotnet/roslyn-compiler for second review |
|
How can we see the delta from what the BCL sources were to what you added as a part of moving to Roslyn? I'm less interested in reviewing the BCL sources (battle tested, already reviewed, etc ...). Think it's more interesting for us to look at the delta to see what has changed and evaluate that. |
|
@jaredpar There is no exact mirror for this type in the BCL. The closest we have is the AVL-backed Note that I followed the pattern from earlier immutable types in this library and made |
| /// <inheritdoc cref="ImmutableHashSet{T}.Clear()"/> | ||
| public ImmutableSegmentedHashSet<T> Clear() | ||
| { | ||
| var self = this; |
There was a problem hiding this comment.
Unsure what the goal of this pattern is here. Can you elaborate?
I can only see this being of value if you're protecting against mixed read / writes of this value in a location. Don't think we generally protect against incorrect uses like that.
There was a problem hiding this comment.
Good catch. This type appears to be missing the equivalent of this notice which is applied to ImmutableSegmentedList<T>:
roslyn/src/Dependencies/Collections/ImmutableSegmentedList`1.cs
Lines 59 to 69 in 519058e
There was a problem hiding this comment.
I'll file a follow-up issue to add this documentation and implement the value builder.
Builds on #54574