Skip to content

[.NET 10 rc1] regression in Type.GetType() performance on Android #118747

@jonathanpeppers

Description

@jonathanpeppers

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:

Image

[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:

Image

[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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions