Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make virtual delegate targets less costly #87308

Merged
merged 3 commits into from
Jun 16, 2023

Conversation

MichalStrehovsky
Copy link
Member

Saves 1.5% on the Stage2 app.

We make sure delegate targets are reflection visible to support Delegate.GetMethodInfo. When I originally did this work in #70198 I made a shortcut to avoid yet another node kind in the system (with a giant comment explaining what the problem is). But there's a lot of benefit in having this new node for apps with many reflection visible virtual methods.

Cc @dotnet/ilc-contrib

Saves 1.5% on the Stage2 app.

We make sure delegate targets are reflection visible to support Delegate.GetMethodInfo. When I originally did this work in dotnet#70198 I made a shortcut to avoid yet another node kind in the system (with a giant comment explaining what the problem is). But there's a lot of benefit in having this new node for apps with many reflection visible virtual methods.
@ghost
Copy link

ghost commented Jun 9, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Saves 1.5% on the Stage2 app.

We make sure delegate targets are reflection visible to support Delegate.GetMethodInfo. When I originally did this work in #70198 I made a shortcut to avoid yet another node kind in the system (with a giant comment explaining what the problem is). But there's a lot of benefit in having this new node for apps with many reflection visible virtual methods.

Cc @dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@jkotas
Copy link
Member

jkotas commented Jun 10, 2023

Test failure looks related:

Method `Mono.Linker.Tests.Cases.DataFlow.StaticInterfaceMethodDataflow.DamOnGenericKeepsMethod.ImplIFoo.VirtualMethod()' should have been kept\nExpected: True\nActual: False

@vitek-karas
Copy link
Member

The test infra reacts to ReflectableMetod nodes, not the new node type. That said I don't see why the test in question would have anything marked as a delegate target.

@MichalStrehovsky
Copy link
Member Author

The test that's failing is this one:

[Kept]
static class DamOnGenericKeepsMethod
{
[Kept]
interface IFoo
{
[Kept]
public static virtual void VirtualMethod () { }
}
[Kept]
[KeptInterface (typeof (IFoo))]
class ImplIFoo : IFoo
{
[Kept]
public static void VirtualMethod () { }
}
[Kept]
static void MethodWithDamOnType<
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
T> ()
{
}
[Kept]
public static void Test ()
{
MethodWithDamOnType<IFoo> ();
var _ = typeof (ImplIFoo);
}
}

I can't think of any reason why ImplIFoo.VirtualMethod should be kept besides Type.GetInterfaceMap. Can anyone see other way how that would be observable?

If there isn't any, I'd suggest we just disable this test on #89157 and move on with life. If that issue is ever fixed we'd need to make this marking conditional on GetInterfaceMap being called somewhere in the app because 1.5% is a lot to leave on the table.

Add a variation of the test which actually keeps the method
@vitek-karas
Copy link
Member

I think you're correct - the method is not needed.
I updated the test and also added a variation which actually calls the method to make sure it's kept.

@MichalStrehovsky

This comment was marked as off-topic.

@azure-pipelines

This comment was marked as off-topic.

@MichalStrehovsky
Copy link
Member Author

@vitek-karas could you have a look?

Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - thanks!

@MichalStrehovsky MichalStrehovsky merged commit 35a5afb into dotnet:main Jun 16, 2023
@MichalStrehovsky MichalStrehovsky deleted the virtdel branch June 16, 2023 00:55
@ghost ghost locked as resolved and limited conversation to collaborators Jul 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants