Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] use ToJniName(type, cache) (#7211)
Browse files Browse the repository at this point in the history
I noticed there might be a performance regression in .NET 7 when
building a .NET MAUI project, in the `<GenerateJavaStubs/>` 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 <<java.interop.tools.javacallablewrappers!Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniName(class Mono.Cecil.TypeDefinition)>>

This was the `JavaNativeTypeManager.ToJniName()` overload that did
not take a `TypeDefinitionCache`.  I found one instance of this in
`<GenerateJavaStubs/>`.

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.
  • Loading branch information
jonathanpeppers authored Jul 27, 2022
1 parent 79be326 commit c3f00cd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c3f00cd

Please sign in to comment.