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

Remove Delegate.Method use in EventRegistrationTokenTable<T> #1444

Closed
Sergio0694 opened this issue Jan 14, 2024 · 0 comments · Fixed by #1448
Closed

Remove Delegate.Method use in EventRegistrationTokenTable<T> #1444

Sergio0694 opened this issue Jan 14, 2024 · 0 comments · Fixed by #1448
Labels
AOT performance Related to performance work trimming
Milestone

Comments

@Sergio0694
Copy link
Member

Overview

NativeAOT in .NET 9 is getting better trimming when using delegates (specifically, allowing delegate targets to not be considered reflection visible, see dotnet/runtime#96166). But, this is currently completely blocked because we're accessing Delegate.Method in our EventRegistrationTokenTable<T> type, which completely disables this optimization (as it could otherwise break):

uint handlerHashCode;
global::System.Delegate[] invocationList = ((global::System.Delegate)(object)handler).GetInvocationList();
if (invocationList.Length == 1)
{
handlerHashCode = (uint)invocationList[0].Method.GetHashCode();
}
else
{
handlerHashCode = (uint)handler.GetHashCode();
}
ulong tokenValue = ((ulong)(uint)typeof(T).GetHashCode() << 32) | handlerHashCode;
return new EventRegistrationToken { Value = (long)tokenValue };

We need to drop that Delegate.Method use to allow saving a fair amount of binary size with NativeAOT builds.
With a minimal WinRT component, doing so saves over 200 KB:

image

See: dotnet/runtime#96947.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AOT performance Related to performance work trimming
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants