-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Description
In the below program we miss a devirtualization opportunity in Method due to the Unsafe.As.
IFace has a single implementor but RyuJIT doesn't even ask for it.
using System;
using System.Runtime.CompilerServices;
interface IFace
{
void Frob();
}
class Program : IFace
{
public static IFace s_inst = new Program();
public object inst;
public Program() => inst = s_inst;
public void Frob() { }
[MethodImpl(MethodImplOptions.NoInlining)]
public void Method() => Unsafe.As<IFace>(inst).Frob();
static void Main()
{
new Program().Method();
}
}I noticed this in the pattern from here as I was looking why interface dispatch is so hot (2.7% of samples spent in RhpInterfaceDispatch1 alone) in BasicMinimalApis:
runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs
Line 719 in 05a3d36
| return Unsafe.As<IValueTaskSource<TResult>>(obj).GetStatus(_token) != ValueTaskSourceStatus.Pending; |
Cc @EgorBo
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI