Skip to content

Commit 6e9c3d7

Browse files
[Mono.Android] delay JNINativeWrapper.get_runtime_types() (#7913)
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.
1 parent 3d8a4ee commit 6e9c3d7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Mono.Android/Android.Runtime/JNINativeWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ public static Delegate CreateDelegate (Delegate dlg)
3434
if (dlg.Method == null)
3535
throw new ArgumentException ();
3636

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

46+
get_runtime_types ();
47+
4848
var ret_type = dlg.Method.ReturnType;
4949
var parameters = dlg.Method.GetParameters ();
5050
var param_types = new Type [parameters.Length];

0 commit comments

Comments
 (0)