Consider switching to reference-based value comparer when a primitive collection is immutable/read-only
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
Our default value comparer(s) for primitive collections do deep comparison, i.e. they check equality for each and every element. When we implement nested primitive collections (#30713), this will have to be recursive.
If the primitive collection type is known to be immutable (e.g. implements [IImmutableList](https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable.iimmutablelist-1?view=net-7.0&source=recommendations)), we can instead switch to the much cheaper reference comparison instead.
One possible objection here is that the immutable list may contain mutable elements, in which case the value comparer would miss something being changed (IIRC we discussed this and decided its OK).
Contributor guide
Assessment
This issue has not been assessed yet.