Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/8.0] Emit less metadata for not-reflection-visible types #91703

Merged
merged 5 commits into from
Sep 11, 2023

Commits on Sep 6, 2023

  1. Emit less metadata for not-reflection-visible types

    In .NET 8 we massively regressed the size of an empty WinForms app. A WinForms app now brings in a big chunk of WPF with it. I traced it down to the `ICommand` interface having a WPF `TypeConverter` and `ValueSerializer` attribute on it: https://github.com/dotnet/runtime/blob/04bd438844482c907062583153a43a9e3b37dbb8/src/libraries/System.ObjectModel/src/System/Windows/Input/ICommand.cs#L13-L16.
    
    An empty app will have a call to a method on `ICommand`, but nothing actually implements `ICommand`. Previously this would mean we generate an unconstructed `MethodTable` for `ICommand`, the unconstructed `MethodTable`s get no reflection metadata, and that's the end of the story.
    
    After #85810 however, the reflection stack can no longer reason about `MethodTable`s that don't have reflection metadata, so we need to generate it. This means we end up with the custom attribute and all the reflection dataflow that comes out of it.
    
    But this metadata is not actually visible in trim safe apps (the only place where reflection could see these method tables in trim safe code is if they're used in a type comparison `x == typeof(Foo)` and we were able to optimize the method table to the unconstructed version because of that). So we can generate less of it and still get away with it.
    
    In this PR I'm adding support for skipping generation of custom attribute metadata for such types. The size of an empty WinForms app goes from 50-something MB to 20-something MB. I think we'll be able to further reduce this number to ~7 MB or less because 12 MB of this are embedded resources that look designer related.
    MichalStrehovsky authored and github-actions committed Sep 6, 2023
    Configuration menu
    Copy the full SHA
    c51af35 View commit details
    Browse the repository at this point in the history
  2. CR feedback

    MichalStrehovsky authored and github-actions committed Sep 6, 2023
    Configuration menu
    Copy the full SHA
    634f516 View commit details
    Browse the repository at this point in the history

Commits on Sep 11, 2023

  1. Configuration menu
    Copy the full SHA
    2d83aff View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8a8f852 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    fca244c View commit details
    Browse the repository at this point in the history