Skip to content

DesignerAttribute/EditorAttribute size implications #92043

Closed

Description

@MichalStrehovsky

We annotated DesignerAttribute/EditorAttribute such that they preserve things on the type that is referred from the attribute.

These two attributes have huge size impact on WinForms - I'm seeing 25+%.

We should ideally do something about this.

  1. Should they actually be annotated? Would we ever expect a trimmed app to use these? (Removing the annotation would be a breaking change, but the break might be warranted.)
  2. If they should be annotated, do we want a feature switch to drop the attributes? I experimentally tried the thing in details below and saw 25+% savings.
  3. Should the default value of the feature switch be to remove them?
Diff (click to expand)
diff --git a/src/libraries/System.ComponentModel.Primitives/src/ILLink/ILLink.LinkAttributes.xml b/src/libraries/System.ComponentModel.Primitives/src/ILLink/ILLink.LinkAttributes.xml
new file mode 100644
index 00000000000..69c54060589
--- /dev/null
+++ b/src/libraries/System.ComponentModel.Primitives/src/ILLink/ILLink.LinkAttributes.xml
@@ -0,0 +1,10 @@
+<linker>
+  <assembly fullname="System.ComponentModel.Primitives" feature="System.ComponentModel.Designer.IsSupported" featurevalue="false">
+    <type fullname="System.ComponentModel.DesignerAttribute">
+      <attribute internal="RemoveAttributeInstances" />
+    </type>
+    <type fullname="System.ComponentModel.EditorAttribute">
+      <attribute internal="RemoveAttributeInstances" />
+    </type>
+  </assembly>
+</linker>
diff --git a/src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj b/src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj
index fe840c389fd..16e8cc1ef0f 100644
--- a/src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj
+++ b/src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj
@@ -7,6 +7,9 @@
     -->
     <GenerateResxSourceIncludeDefaultValues>true</GenerateResxSourceIncludeDefaultValues>
   </PropertyGroup>
+  <ItemGroup>
+    <ILLinkLinkAttributesXmls Include="ILLink\ILLink.LinkAttributes.xml" />
+  </ItemGroup>
   <ItemGroup>
     <Compile Include="System\ComponentModel\ISynchronizeInvoke.cs" />
     <Compile Include="System\ComponentModel\BrowsableAttribute.cs" />

Activity

  1. added
    linkable-framework
    on Sep 14, 2023
  2. ghost added
    untriaged
    on Sep 14, 2023
  3. Wraith2 commented on Sep 14, 2023

    @Wraith2
    Contributor

    If you use a PropertyGrid then having editor attributes is required in order to customize the UI of types in the grid. So I think they're often required.

  4. steveharter commented on Sep 18, 2023

    @steveharter
    Contributor

    These two attributes have huge size impact on WinForms - I'm seeing 25+%.

    What is the total size savings, and is it just in System.ComponentModel.Primitives.dll (80K, so 20K savings)?

    Both of these I assume are not needed at runtime (only design-time). Do we have a mechanism during publish to distinguish between that and remove such artifacts? If not, could\should we add one?

    Some history:
    Newer (2020) PR for DesignerAttribute: https://github.com/dotnet/runtime/pull/40425/files
    Older (2016) commit for EditorAttribute: dotnet/corefx@09d2d1b

  5. removed
    untriaged
    on Sep 18, 2023
  6. added this to the Future milestone on Sep 18, 2023
  7. MichalStrehovsky commented on Sep 18, 2023

    @MichalStrehovsky
    MemberAuthor

    What is the total size savings, and is it just in System.ComponentModel.Primitives.dll (80K, so 20K savings)?

    The savings is 6 MB for an empty WinForms app. (21 MB to 15 MB). This is not the size of ComponentModel.Primitives: that's tiny.

    To expand on the "We annotated DesignerAttribute/EditorAttribute such that they preserve things on the type that is referred from the attribute." in the top post: the problem is in the DynamicallyAccessedMembers annotations on these, e.g.:

    public DesignerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName)

    These tell trimming to keep the referenced type, and that's where all the costs come from.

  8. MichalStrehovsky commented on Sep 18, 2023

    @MichalStrehovsky
    MemberAuthor
  9. MichalStrehovsky commented on Feb 22, 2024

    @MichalStrehovsky
    MemberAuthor

    Fixed in #98378.

  10. locked and limited conversation to collaborators on Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.ComponentModellinkable-framework

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions