Skip to content

Using Options Validation Source Generator results in increased app size #106366

Closed
@eerhardt

Description

@eerhardt

Switching the ASP.NET Core's TodosApi benchmark app (a.k.a. "Stage 2") to use the Microsoft.Extensions.Options validation source generator causes the app to go from 18.1 MB to 19.5 MB on win-x64.

Repro steps

  1. Clone https://github.com/aspnet/Benchmarks
  2. cd src\BenchmarksApps\TodosApi
  3. dotnet publish
  4. Checkout eerhardt/Benchmarks@c667d28
  5. dotnet publish

Expected result

The 2 publishes should result in roughly the same size app

Actual result

The 2nd app is almost 8% larger (18.1 => 19.5).

Logs

You can open the following in sizoscope to view the difference between the apps.

todos-before.zip
todos-after.zip

Doing an initial investigation, I believe what is happening is that including System.ComponentModel code into the graph causes ICustomTypeDescriptor to be included, which since Npgsql's ConnectionStringBuilder (and our System.Data.Common ConnectionStringBuilder) implements ICustomTypeDescriptor. In order to make that usage trim-compatible, we added [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] to the base DbConnectionStringBuilder. That class is also an IDictionary, which means all interface methods on the collection types are being preserved - across every collection in the app.

image

image

Related: #97057

cc @MichalStrehovsky @tarekgh @steveharter @DamianEdwards

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions