-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
When building the default dotnet new android
runtime application, we can see that the following runtimeconfig.json
file is generated:
{
"runtimeOptions": {
"tfm": "net10.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "10.0.0-preview.2.25119.7"
},
{
"name": "Microsoft.Android",
"version": "**FromWorkload**"
}
],
"configProperties": {
"System.Diagnostics.Metrics.Meter.IsSupported": false,
"Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability": false,
"System.ComponentModel.DefaultValueAttribute.IsSupported": true,
"System.ComponentModel.Design.IDesignerHost.IsSupported": false,
"System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization": false,
"System.ComponentModel.TypeDescriptor.IsComObjectDescriptorSupported": false,
"System.Data.DataSet.XmlSerializationIsSupported": false,
"System.Diagnostics.Debugger.IsSupported": false,
"System.Diagnostics.Tracing.EventSource.IsSupported": false,
"System.Globalization.Invariant": false,
"System.Linq.Enumerable.IsSizeOptimized": true,
"System.Net.Http.EnableActivityPropagation": false,
"System.Net.Http.UseNativeHttpHandler": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Resources.ResourceManager.AllowCustomResourceTypes": false,
"System.Resources.UseSystemResourceKeys": true,
"System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported": true,
"System.Runtime.InteropServices.BuiltInComInterop.IsSupported": false,
"System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting": false,
"System.Runtime.InteropServices.EnableCppCLIHostActivation": false,
"System.Runtime.InteropServices.Marshalling.EnableGeneratedComInterfaceComImportInterop": false,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.StartupHookProvider.IsSupported": false,
"System.Text.Encoding.EnableUnsafeUTF7Encoding": false,
"System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault": true,
"System.Threading.Thread.EnableAutoreleasePool": false,
"Xamarin.Android.Net.UseNegotiateAuthentication": false,
"Switch.System.Reflection.ForceInterpretedInvoke": true,
"Microsoft.Extensions.DependencyInjection.DisableDynamicEngine": true
}
}
}
After a discussion on Discord, it appears that most of those options aren't needed and might not be checked at run time, because the relevant code could have been trimmed away by the trimmer.
Each of those options is passed to CoreCLR runtime at initialization and each of them (both the name and the value) needs to be converted from UTF-8 to Unicode, which means memory allocation and the actual conversion. If a property isn't used, it means the time processing the property and memory allocated for it are both wasted.
It would be very good if we were able to omit unnecessary properties/switches from the JSON file. This could be done in two ways, it appears:
- By adding support to the trimmer to annotate in msbuild those properties it trimmed out, so we can skip them when building the application.
- By adding a way to learn what is the default value of each switch/property, so that we can go over the list and decide which options are set to their defaults, to skip them when building the application.