[Performance improvement] Minimize number of properties placed in the runtimeconfig.json file

Open
#112,956 7 comments 0 reactions 1 assignee View on GitHub

@steveisok is already working on this.

Since Feb 26, 2025.

Assessment

This issue has not been assessed yet.

Description

area-VM-meta-mono os-android

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:

  1. By adding support to the trimmer to annotate in msbuild those properties it trimmed out, so we can skip them when building the application.
  2. 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.
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.