Skip to content

Commit efead2b

Browse files
[Xamarin.Android.Build.Tasks] fast path for <CheckClientHandlerType/>
`dotnet trace` of a `dotnet new maui` project, I noticed this was happening on *any* build: 65.94ms xamarin.android.build.tasks!Xamarin.Android.Tasks.CheckClientHandlerType.RunTask() Checking outside of a profiler, a `.binlog` says: CheckClientHandlerType = 55 ms This was added in 311b41e, so it is only in main & .NET 8. Maybe when we timed this before, it wasn't a MAUI app? Looking at the stack trace, most of the time is spent loading assemblies with Mono.Cecil. Let's add a check at the beginning for the two most common values: * .NET 6+: `Xamarin.Android.Net.AndroidMessageHandler` * Classic: `Xamarin.Android.Net.AndroidClientHandler` And we can return early in these cases. After these changes, I get: CheckClientHandlerType = 2 ms This should save ~53ms on any build w/ common settings for `$(AndroidHttpClientHandlerType)`.
1 parent f4aed9e commit efead2b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/CheckClientHandlerType.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,21 @@ public class CheckClientHandlerType : AndroidTask
1919
[Required]
2020
public string ValidHandlerType { get; set; }
2121
[Required]
22+
public bool UsingAndroidNETSdk { get; set; }
23+
[Required]
2224
public ITaskItem[] ResolvedAssemblies { get; set; }
2325

2426
public override bool RunTask ()
2527
{
28+
// Fast path for known types
29+
if (UsingAndroidNETSdk) {
30+
if (ClientHandlerType == "Xamarin.Android.Net.AndroidMessageHandler")
31+
return !Log.HasLoggedErrors;
32+
} else {
33+
if (ClientHandlerType == "Xamarin.Android.Net.AndroidClientHandler")
34+
return !Log.HasLoggedErrors;
35+
}
36+
2637
string[] types = ClientHandlerType.Split (',');
2738
string type = types[0].Trim ();
2839
string assembly = "Mono.Android";

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
498498
<CheckClientHandlerType
499499
ClientHandlerType="$(AndroidHttpClientHandlerType)"
500500
ValidHandlerType="$(ValidAndroidHttpClientHandlerBaseType)"
501+
UsingAndroidNETSdk="$(UsingAndroidNETSdk)"
501502
ResolvedAssemblies="$(OutDir)$(TargetFileName);@(ReferencePath);@(ReferenceDependencyPaths)"
502503
/>
503504
</Target>

0 commit comments

Comments
 (0)