Skip to content

Remove MS.Extensions.Logging.Console's dependency on ConfigurationBinder #81931

Closed

Description

@eerhardt

In measuring the size of a NativeAOT published ASP.NET app, a considerable amount of size is added when using Console logging.

dotnet new api -aot and dotnet publish on win-x64: 13.2 MB. Removing the line builder.Logging.AddConsole(): 12.1 MB.

From my investigation, I've determined that ~860KB of size comes from using the ConfigurationBinder, which also pulls in Sytem.ComponentModel.TypeConverter. One reason this is so big is because a bunch of methods on ICollection/IList can be trimmed if we don't include ConfigurationBinder/TypeConverter. There are a lot of generic instantiations of collections (Dictionary, List, etc), and all these interface methods across scores of collection types add up. The methods in the System.Collections.Generic namespace drop by 343 KB alone.

For a full picture of all the code that can be trimmed here, diff the following mstat dumps:

no-configbinder-console.txt was created using eerhardt@af48374.
configbinder-console.txt was created from main

To eliminate this code from the application, we should remove the ConfigurationBinder usages in Logging.Console. They come from 2 places:

LoggerProviderOptions.RegisterProviderOptions<ConsoleLoggerOptions, ConsoleLoggerProvider>(builder.Services);

builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<TOptions>, ConsoleLoggerFormatterConfigureOptions<TFormatter, TOptions>>());

And instead we can hand-write the "configuration => options" deserialization code. This can also improve startup performance, since we won't be using Reflection here.

Another option would be to use #44493, but that isn't available yet. We can always hand-write the code for now, and use the source generator later once available.

Activity

  1. added this to the 8.0.0 milestone on Feb 10, 2023
  2. self-assigned this
    on Feb 10, 2023
  3. tarekgh commented on Feb 11, 2023

    @tarekgh
    Member

    CC @layomia for awareness

  4. added a commit that references this issue on Feb 14, 2023
    583731d
  5. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Feb 14, 2023
  6. added a commit that references this issue on Feb 16, 2023
    0f129e4
  7. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Feb 16, 2023
  8. ghost locked as resolved and limited conversation to collaborators on Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions