dotnet / dotnet/efcore

Consider switching to reference-based value comparer when a primitive collection is immutable/read-only

Open
#31,374 1 comment 0 reactions 0 assignees View on GitHub
area-model-building area-perf customer-reported
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.