From d3828368f5473b236b8498fd38a2c280e334e8cf Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 23 Apr 2024 11:17:44 -0700 Subject: [PATCH] Don't cache 'RegisterTypeRuntimeClassNameLookup' --- src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs b/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs index 03a2cb0a0..9e258aede 100644 --- a/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs +++ b/src/Authoring/WinRT.SourceGenerator/AotOptimizer.cs @@ -912,6 +912,9 @@ internal static void GenerateVtableLookupTable(Action addSource, // referenced and that can run into issues because they can have their own lookup tables that // get registered in their module initializer, but will fail to due to the reader writer lock we have around it // (i.e. we are traversing the lookup tables here while one is being registered). + // + // Note: just like with the authoring metadata function, we don't use a method group expression but rather construct a 'Func' ourselves. + // This is done to opt-out of the implicit caching that Roslyn does. We don't need that extra code and overhead, as this is only done once. var hasRuntimeClasNameEntries = value.vtableAttributes.Any(v => !string.IsNullOrEmpty(v.RuntimeClassName)); if (value.vtableAttributes.Any()) { @@ -930,7 +933,7 @@ internal static class {{classPrefix}}GlobalVtableLookup internal static void InitializeGlobalVtableLookup() { ComWrappersSupport.RegisterTypeComInterfaceEntriesLookup(LookupVtableEntries); - {{(hasRuntimeClasNameEntries ? "ComWrappersSupport.RegisterTypeRuntimeClassNameLookup(LookupRuntimeClassName);" : "")}} + {{(hasRuntimeClasNameEntries ? "ComWrappersSupport.RegisterTypeRuntimeClassNameLookup(new Func(LookupRuntimeClassName));" : "")}} } private static ComWrappers.ComInterfaceEntry[] LookupVtableEntries(Type type)