dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.42k stars 4.76k forks source link

Remove Helper Method Frames (HMF) from Reflection #109996

Open AaronRobinsonMSFT opened 2 days ago

AaronRobinsonMSFT commented 2 days ago

Convert RuntimeMethodHandle.GetDeclaringType() to managed and QCall. Convert RuntimeTypeHandle.GetElementType() to managed. Correct nullability in signature and usage. Convert RuntimeTypeHandle.GetDeclaringType() to managed and QCalls. Remove GetRuntimeTypeHelper().

dotnet-policy-service[bot] commented 2 days ago

Tagging subscribers to this area: @mangod9 See info in area-owners.md if you want to be subscribed.

AaronRobinsonMSFT commented 2 days ago

@EgorBot -intel -arm64 -perf

using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkRunner.Run<Bench>(args: args);

public class Bench
{
    struct S;

    [Benchmark]
    public Type Nested() => typeof(S).DeclaringType;

    [Benchmark]
    public Type NotNested() => typeof(Bench).DeclaringType;

    [Benchmark]
    public Type RefElementType() => typeof(Bench[]).GetElementType();

    [Benchmark]
    public Type ValueElementType() => typeof(S[]).GetElementType();
}
AaronRobinsonMSFT commented 2 days ago

@EgorBot -x64 -arm64 -profiler

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Bench
{
    struct S;

    [Benchmark]
    public Type Nested() => typeof(S).DeclaringType;

    [Benchmark]
    public Type NotNested() => typeof(Bench).DeclaringType;

    [Benchmark]
    public Type RefElementType() => typeof(Bench[]).GetElementType();

    [Benchmark]
    public Type ValueElementType() => typeof(S[]).GetElementType();
}
EgorBo commented 2 days ago

@AaronRobinsonMSFT the bot complained that -profiler flag should be used when there are not more than 3 [Benchmark] attributes. I think I should improve error reporting 🙂

EgorBo commented 2 days ago

@EgorBot -x64 -arm64

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Bench
{
    struct S;

    [Benchmark]
    public Type Nested() => typeof(S).DeclaringType;

    [Benchmark]
    public Type NotNested() => typeof(Bench).DeclaringType;

    [Benchmark]
    public Type RefElementType() => typeof(Bench[]).GetElementType();

    [Benchmark]
    public Type ValueElementType() => typeof(S[]).GetElementType();
}
AaronRobinsonMSFT commented 1 day ago

@EgorBot -x64 -arm64 -profiler

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

public class Bench
{
    struct S;

    [Benchmark]
    public Type RefElementType() => typeof(Bench[]).GetElementType();

    [Benchmark]
    public Type ValueElementType() => typeof(S[]).GetElementType();
}