Skip to content

Support devirtualizing/inlining Comparer<T>.Default.Compare #47343

@stephentoub

Description

@stephentoub

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?

cc: @AndyAyersMS, @eiriktsarpalis

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions