-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add back IComparable-based optimization to FrozenDictionary/Set #84301
Conversation
We previously had an optimization in FrozenDictionary/Set that special-cased a small number of value types when the default comparer is used... if that type was IComparable, we would sort the types, which would then a) enable us to immediately reject items larger than the known max, and b) enable us to stop searching once we hit an item larger than the one for which we were searching (which then implicitly also immediately rules out items smaller than the known min). We removed that optimization in general because some prominent IComparable implementations don't always work, in particular container types like ValueTuple that implement IComparable but then it's only functional if the contained types are also comparable. This commit puts it back for an allow-list of types.
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsWe previously had an optimization in FrozenDictionary/Set that special-cased a small number of value types when the default comparer is used... if that type was IComparable, we would sort the types, which would then a) enable us to immediately reject items larger than the known max, and b) enable us to stop searching once we hit an item larger than the one for which we were searching (which then implicitly also immediately rules out items smaller than the known min). We removed that optimization in general because some prominent IComparable implementations don't always work, in particular container types like ValueTuple that implement IComparable but then it's only functional if the contained types are also comparable. This commit puts it back for an allow-list of types.
|
src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/Constants.cs
Show resolved
Hide resolved
...lections.Immutable/src/System/Collections/Frozen/SmallValueTypeComparableFrozenDictionary.cs
Outdated
Show resolved
Hide resolved
...tem.Collections.Immutable/src/System/Collections/Frozen/SmallValueTypeComparableFrozenSet.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/Constants.cs
Outdated
Show resolved
Hide resolved
Just for information, what determines that an
|
It's a minor detail of this particular internal optimization. There's no opting into it. This is really just special-casing a few known types to enable a specific optimization with them. |
We previously had an optimization in FrozenDictionary/Set that special-cased a small number of value types when the default comparer is used... if that type was IComparable, we would sort the types, which would then a) enable us to immediately reject items larger than the known max, and b) enable us to stop searching once we hit an item larger than the one for which we were searching (which then implicitly also immediately rules out items smaller than the known min).
We removed that optimization in general because some prominent IComparable implementations don't always work, in particular container types like ValueTuple that implement IComparable but then it's only functional if the contained types are also comparable. This commit puts it back for an allow-list of types.