Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid Attribute.GetCustomAttributes overheads when inherit==true is useless #54402

Merged
merged 1 commit into from
Jun 21, 2021

Conversation

stephentoub
Copy link
Member

Just stop doing unnecessary work.

Method Toolchain Mean Ratio Allocated
Get \main\corerun.exe 826.7 ns 1.00 664 B
Get \pr\corerun.exe 488.1 ns 0.59 104 B
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Reflection;

[MemoryDiagnoser]
public class Program
{
    static void Main(string[] args) => BenchmarkSwitcher.FromAssemblies(new[] { typeof(Program).Assembly }).Run(args);

    private PropertyInfo _prop = typeof(B).GetProperty("MyProp");

    [Benchmark]
    public Attribute[] Get() => Attribute.GetCustomAttributes(_prop, inherit: true);
}

class A { }

class B : A
{
    [My]
    public int MyProp { get; set; }
}

class MyAttribute : Attribute { }

@stephentoub stephentoub added this to the 6.0.0 milestone Jun 18, 2021
@jkotas
Copy link
Member

jkotas commented Jun 21, 2021

Failure is #54125

@jkotas jkotas merged commit 89b39c5 into dotnet:main Jun 21, 2021
@stephentoub
Copy link
Member Author

Failure is #54125

Thanks. I kept trying to figure out how my changes were causing these :)

@stephentoub stephentoub deleted the inheritattributes branch June 21, 2021 18:02
@ghost ghost locked as resolved and limited conversation to collaborators Jul 21, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

2 participants