Unify managed runtime type name parsers (#83484)
authorJan Kotas <jkotas@microsoft.com>
Sat, 25 Mar 2023 03:46:49 +0000 (20:46 -0700)
committerGitHub <noreply@github.com>
Sat, 25 Mar 2023 03:46:49 +0000 (20:46 -0700)
commit91b93eb22bc7d9029a38469e55aa72d52c087834
treed2b10958fafb0177fbd0abea9b8d05dc1283ae6d
parent35a39e97345abfda05e14f609759760b37ddeb4d
Unify managed runtime type name parsers (#83484)

Contributes to #72833 and #77868

The performance effect of this change on typical use of `Type.GetType` like `Type.GetType("MyType, MyAssembly")` is in the noise range. The typical use of `Type.GetType` spends most of the time in assembly loader and type loader. The time spent by parsing the type name is small fraction of the total and the performance improvement is hardly noticeable.

When the type name parser performance is measured in isolation, it is several times faster compared to the existing unmanaged CoreCLR type name parser. For example:
```
Type.GetType("System.Object, System.Private.CoreLib",
       assemblyResolver: (an) => typeof(object).Assembly,
       typeResolver: (assembly, name, ignoreCase) => typeof(object));
```
is about 3x faster with this change on CoreCLR.

Co-authored-by: Aaron Robinson <arobins@microsoft.com>
44 files changed:
src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj
src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs
src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeModule.cs
src/coreclr/System.Private.CoreLib/src/System/Reflection/TypeNameParser.CoreCLR.cs [new file with mode: 0644]
src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/Type.CoreCLR.cs
src/coreclr/System.Private.CoreLib/src/System/TypeNameParser.cs [deleted file]
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/AssemblyBinder.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Core/Execution/ExecutionDomain.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/ReflectionExecutionDomainCallbacks.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ReflectionHelpers.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Assemblies/NativeFormat/NativeFormatRuntimeAssembly.GetTypeCore.CaseInsensitive.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Assemblies/NativeFormat/NativeFormatRuntimeAssembly.GetTypeCore.CaseSensitive.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Assemblies/NativeFormat/NativeFormatRuntimeAssembly.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Assemblies/RuntimeAssemblyInfo.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/Helpers.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeResolver.NativeFormat.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeResolver.cs
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeParsing/GetTypeOptions.cs [deleted file]
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeParsing/TypeLexer.cs [deleted file]
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeParsing/TypeName.cs [deleted file]
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeParsing/TypeParser.cs [deleted file]
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/TypeNameParser.NativeAot.cs [new file with mode: 0644]
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs
src/coreclr/nativeaot/System.Private.DisabledReflection/src/Internal/Reflection/ReflectionExecutionDomainCallbacksImplementation.cs
src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecution.cs
src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ReflectionExecutionDomainCallbacksImplementation.cs
src/coreclr/vm/appdomain.cpp
src/coreclr/vm/assemblynative.cpp
src/coreclr/vm/assemblynative.hpp
src/coreclr/vm/commodule.cpp
src/coreclr/vm/commodule.h
src/coreclr/vm/corelib.h
src/coreclr/vm/qcallentrypoints.cpp
src/coreclr/vm/typeparse.cpp
src/coreclr/vm/typeparse.h
src/libraries/Common/src/System/Reflection/TypeNameParser.cs [new file with mode: 0644]
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.cs
src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj
src/mono/System.Private.CoreLib/src/System/Reflection/TypeNameParser.Mono.cs [new file with mode: 0644]
src/mono/System.Private.CoreLib/src/System/TypeNameParser.cs [deleted file]