From f2c938d7d5921852299a25e0ea5c02f9bf1a1d54 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Wed, 27 Jul 2022 08:56:34 -0500 Subject: [PATCH] [Xamarin.Android.Build.Tasks] use `ToJniName (type, cache)` I noticed there might be a performance regression in .NET 7 when building a .NET MAUI project, in the `` MSBuild task: .NET 6: GenerateJavaStubs = 799 ms xa main: GenerateJavaStubs = 912 ms When reviewing what PerfView shows, I saw: 54.31ms (5.7%) module java.interop.tools.javacallablewrappers <> This was the overload that did not take in a `TypeDefinitionCache`. I found one instance of this in ``. This doesn't seem like the .NET 7 regression, because it has always been this way. However, it seems to help quite a bit: GenerateJavaStubs = 825 ms GenerateJavaStubs = 867 ms This probably saves around ~50ms in this task. --- src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs index 52317659f12..6906f31e0a0 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs @@ -346,7 +346,7 @@ void Run (DirectoryAssemblyResolver res) regCallsWriter.WriteLine ("\t\t// Application and Instrumentation ACWs must be registered first."); foreach (var type in javaTypes) { if (JavaNativeTypeManager.IsApplication (type, cache) || JavaNativeTypeManager.IsInstrumentation (type, cache)) { - string javaKey = JavaNativeTypeManager.ToJniName (type).Replace ('/', '.'); + string javaKey = JavaNativeTypeManager.ToJniName (type, cache).Replace ('/', '.'); regCallsWriter.WriteLine ("\t\tmono.android.Runtime.register (\"{0}\", {1}.class, {1}.__md_methods);", type.GetAssemblyQualifiedName (cache), javaKey); }