Repository navigation
Closed
Labels
area-System.ComponentModellinkable-frameworkIssues associated with delivering a linker friendly framework
Milestone
Description
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.
- 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.)
- 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.
- 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" />Reacted by Paulus Pärssinen
Metadata
Metadata
Assignees
Labels
area-System.ComponentModellinkable-frameworkIssues associated with delivering a linker friendly framework
Activity
Wraith2 commentedon Sep 14, 2023
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.
steveharter commentedon Sep 18, 2023
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
MichalStrehovsky commentedon Sep 18, 2023
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.:
runtime/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerAttribute.cs
Line 20 in e1ca02f
These tell trimming to keep the referenced type, and that's where all the costs come from.
MichalStrehovsky commentedon Sep 18, 2023
Cc @eerhardt
MichalStrehovsky commentedon Feb 22, 2024
Fixed in #98378.