-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
I've been comparing startup time of the .NET MAUI project template on Android. .NET 9 vs .NET 10.
.NET 10 is slower, and one of the contributors is Type.GetType():
.NET 9: 30.52ms System.Private.CoreLib!System.Type.GetType(string,bool)
.NET 10: 146.77ms System.Private.CoreLib!System.Type.GetType(string,bool)
To verify we weren't just calling it more often, I added some logging in the Android workload and that did not appear to be the case. I did fix this related issue, I found on our side.
I estimate this degrades startup performance for the .NET MAUI template by around 115ms or so on a Pixel 5 device.
Comparing the two code paths, I can see new logic happening in .NET 10:
runtime/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs
Lines 28 to 34 in c5e7fac
| [RequiresUnreferencedCode("The type might be removed")] | |
| [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod | |
| public static Type? GetType(string typeName, bool throwOnError, bool ignoreCase) | |
| { | |
| StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; | |
| return GetType(typeName, null, null, throwOnError, ignoreCase, false, ref stackMark); | |
| } |
While previously it just called:
runtime/src/mono/System.Private.CoreLib/src/System/Type.Mono.cs
Lines 28 to 34 in 4baf26c
| [RequiresUnreferencedCode("The type might be removed")] | |
| [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod | |
| public static Type? GetType(string typeName, bool throwOnError, bool ignoreCase) | |
| { | |
| StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; | |
| return RuntimeType.GetType(typeName, throwOnError, ignoreCase, ref stackMark); | |
| } |
Configuration
Build from vmr, .NET 10.0.100-rc.1.25412.102
Regression?
Yes
Data
dotnet-trace output: maui-type.gettype.zip
Analysis
Java interop's current implementation calls Type.GetType() a lot. .NET MAUI then makes many Java interop calls.
I made a BenchmarkDotNet project to test this, but the problem does not appear to occur on Windows desktop with CoreCLR. So, this could be specific to Mono or Android.