Skip to content

Commit

Permalink
[Mono.Android] delay JNINativeWrapper.get_runtime_types() (#7913)
Browse files Browse the repository at this point in the history
Reviewing `dotnet-trace` output, I noticed in a `dotnet new maui` app
on a Pixel 5:

	6.38ms mono.android!Android.Runtime.JNINativeWrapper.CreateDelegate(System.Delegate)
	1.16ms mono.android!Android.Runtime.JNINativeWrapper.get_runtime_types()

We spend ~1ms looking up `AndroidEnvironment.UnhandledException()`
and `AndroidRuntimeInternal.WaitForBridgeProcessing()`.

However, in this app *all* calls go to the "fast path" via
`JNINativeWrapper.CreateBuiltInDelegate()`.  We don't *need* to look
up these methods in this app at all!

Delay the call to `get_runtime_types()` to only when it is needed via
the "slow path".  Will help us a small amount in .NET 8.
  • Loading branch information
jonathanpeppers authored Mar 23, 2023
1 parent 3d8a4ee commit 6e9c3d7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Mono.Android/Android.Runtime/JNINativeWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public static Delegate CreateDelegate (Delegate dlg)
if (dlg.Method == null)
throw new ArgumentException ();

get_runtime_types ();

var delegateType = dlg.GetType ();
var result = CreateBuiltInDelegate (dlg, delegateType);
if (result != null)
Expand All @@ -45,6 +43,8 @@ public static Delegate CreateDelegate (Delegate dlg)
RuntimeNativeMethods.monodroid_log (LogLevel.Debug, LogCategories.Assembly, $"Falling back to System.Reflection.Emit for delegate type '{delegateType}': {dlg.Method}");
}

get_runtime_types ();

var ret_type = dlg.Method.ReturnType;
var parameters = dlg.Method.GetParameters ();
var param_types = new Type [parameters.Length];
Expand Down

0 comments on commit 6e9c3d7

Please sign in to comment.