You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[API Proposal]: Add ImmutableArray.Contains overload that accepts an IEqualityComparer<T> #66758
I recently had a significant inner-loop performance regression when I added an optional IEqualityComparer<T> to my API. I found out that the reason was that I added the optional comparer argument to the Contains invocation on a ImmutableArray<T>.
Apparently there is no such overload, so it the call was directed from:
This caused a significant amount of boxing to IEnumerable<T> each time Contains was called. Most methods in the API at the moment contain overloads that accept an optional IEqualityComparer<T>?, so it was quite surprising that this API did not.
This has a really low risk of breaking something. It should increase the overall performance when Contains is used where the programmer was not aware of this issue.
changed the title [-][API Proposal]: Add ImmutableArray.Contains overload with IEqualityComparer<T>[/-][+][API Proposal]: Add ImmutableArray.Contains overload that accepts an IEqualityComparer<T>[/+]on Mar 17, 2022
Given that it is fairly common for concrete collections to fall back to slower LINQ methods, I'm not necessarily convinced that it's sufficient justification to add another overload in ImmutableArray<T>. There's codegen overhead to adding more methods to generic types, and as you're pointing out it's fairly trivial to express this overload as an extension method.
Given that it is fairly common for concrete collections to fall back to slower LINQ methods, I'm not necessarily convinced that it's sufficient justification to add another overload in ImmutableArray<T>. There's codegen overhead to adding more methods to generic types, and as you're pointing out it's fairly trivial to express this overload as an extension method.
Yes, the required functionality is already present in ImmutableArray.IndexOf, so this can easily be expressed as an extension method.
However that argument would also apply to the single-argument Contains method already present.
Question for whenever this comes to review: I recall that some time ago the review team made a blanket policy that System.Linq.Queryable should be kept in sync with (most) methods in System.Linq.Enumerable. Does it make sense to extend that policy to keep ImmutableArrayExtensions in sync as well?
Looks good as proposed, except we changed from an extension method to an instance method (as this is an overload of the existing Contains(T)). This seems generally applicable to any struct that is IEnumerable that provides a Contains(T) without a Contains(T, IEqualityComparer<T>)... but we couldn't find a second one during the meeting.
Activity
[-][API Proposal]: Add ImmutableArray.Contains overload with IEqualityComparer<T>[/-][+][API Proposal]: Add ImmutableArray.Contains overload that accepts an IEqualityComparer<T>[/+]eiriktsarpalis commentedon Mar 21, 2022
Given that it is fairly common for concrete collections to fall back to slower LINQ methods, I'm not necessarily convinced that it's sufficient justification to add another overload in
ImmutableArray<T>. There's codegen overhead to adding more methods to generic types, and as you're pointing out it's fairly trivial to express this overload as an extension method.ChrML commentedon Mar 21, 2022
Yes, the required functionality is already present in ImmutableArray.IndexOf, so this can easily be expressed as an extension method.
However that argument would also apply to the single-argument Contains method already present.
Joe4evr commentedon Mar 21, 2022
Is it not an option to add this overload to the set of LINQ extensions specialized for
ImmutableArray<T>?ChrML commentedon Mar 21, 2022
I think that's the best option.
eiriktsarpalis commentedon Mar 22, 2022
SGTM, given there's precedent. @ChrML could you update your API proposal to use that namespace?
Joe4evr commentedon Mar 24, 2022
If OP isn't going to update, then I'll place the revised proposal real quick:
ChrML commentedon Mar 24, 2022
I have updated the proposal to what we have discussed here. Sorry for that it took so long.
Joe4evr commentedon Mar 5, 2023
Question for whenever this comes to review: I recall that some time ago the review team made a blanket policy that
System.Linq.Queryableshould be kept in sync with (most) methods inSystem.Linq.Enumerable. Does it make sense to extend that policy to keepImmutableArrayExtensionsin sync as well?bartonjs commentedon May 11, 2023
Looks good as proposed, except we changed from an extension method to an instance method (as this is an overload of the existing
Contains(T)). This seems generally applicable to anystructthat isIEnumerablethat provides aContains(T)without aContains(T, IEqualityComparer<T>)... but we couldn't find a second one during the meeting.