dotnet / linker

389 stars 126 forks source link

Remove linker-specific attributes in 'exe' mode #3038

Open jtschuster opened 2 years ago

jtschuster commented 2 years ago

The linker doesn't remove DynamicallyAccessedMembers, RequiresUnreferencedCode, etc. If we link in 'exe' mode, is there a reason we need to keep them? In library mode it makes sense, but I can't think of why we would need them for a published application.

jtschuster commented 2 years ago

@sbomer pointed out there is a LinkAttributes.xml (link) that removes these and can be enabled with _AggressiveAttributeTrimming property (link), but it doesn't seem to be enabled anywhere in the sdk.

Perhaps this should be the default behavior of the linker, but maybe there's a reason the XML isn't used anywhere anymore.

vitek-karas commented 2 years ago

The aggressive trimming mode should be enabled in Blazor - where the size matters the most. In other verticals we so far didn't enable it because it's more likely to break things. Linker has some functionality to detect if the app will break with this mode - if it sees a type reference to the attribute in question it will produce a warning. But lot of times, the attribute consumption code doesn't have a type reference instead it enumerates all attributes and looks for it by name, which linker can't figure out. If this happens, the app may break.

Basically for now we decided not try to figure out a solid approach for trimming attributes. We maybe want to look into that.

I agree that the trimmer attributes are very likely safe to be removed, but it's a general approach which for now we decided against.

I'm not against doing this for the trimmer attributes (and other Requires... attributes as well), but I think we should try to gather some data - how much size is it going to safe?