-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
dotnet/coreclr#14125 made EqualityComparer<T>.Default an intrinsic recognized by the JIT, teaching the JIT what concrete type of comparer would be used for any given T and enabling EqualityComparer<T>.Default.Equals to be fully devirtualized and inlined. This in turn led to optimizations in managed code, where code that was making heavy use of EqualityComparer<T>.Default as a default implementation added specialized code paths that used EqualityComparer<T>.Default, e.g. in various collections like Dictionary<>.
Comparer<T>.Default could benefit from similar optimizations. Comparer<T>.Default.Compare doesn't show up quite as much as EqualityComparer<T>.Default.Equals, but it still shows up in a lot of places, and there are a variety of collections (e.g. the new PriorityQueue<> being added in .NET 6) that would similarly optimize for Comparer<T>.Default if Comparer<T>.Default.Compare could be devirtualized and inlined.
Is this feasible?