-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Annotate framework assemblies as trimmable #48428
Conversation
This will opt them into trimming with the behavior described at https://github.com/mono/linker/blob/main/docs/design/trimmed-assemblies.md#assemblymetadataistrimmable-true.
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
eng/versioning.targets
Outdated
@@ -20,6 +20,9 @@ | |||
<AssemblyMetadata Include="PreferInbox"> | |||
<Value>True</Value> | |||
</AssemblyMetadata> | |||
<AssemblyMetadata Include="IsTrimmable"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we want to do this blindly? It feels like at least there should be a Condition to allow individual assemblies to turn it off.
Note that today we only analyze the assemblies in the shared fx / runtimepack for ILLink warnings. All OOB assemblies go unanalyzed. Once we have a story for analyzing libraries, we should hook dotnet/runtime
up to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add a condition. Are there any in particular that you think I should turn off to start with? (Would it maybe make sense to turn it off for OOB assemblies and opt them in individually when we analyze them?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, note that the feature as designed isn't tied to the warnings inherently - the attribute just says "trim me" - whether the assembly is linker-safe or not. That said, maybe it makes sense to opt out of trimming in cases where we don't trim a library during the runtime build because it uses too much reflection, like this:
Lines 7 to 8 in 75d5cc3
<!-- Too much private reflection. Do not bother with trimming --> | |
<ILLinkTrimAssembly>false</ILLinkTrimAssembly> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All libraries need to be trimmable in 6.0 but I'd probably exclude netfx build targets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All libraries need to be trimmable in 6.0
I agree we want to get there. But I think we should do it in a pragmatic way. Turning it on for all assemblies and letting people tell us what breaks doesn't seem like the best approach.
My thinking is that once we are done annotating the shared fx libraries, we start analyzing ILLink warnings for OOB libraries. When each library is "clean" of ILLink warnings, we mark it as "Trimmable".
For the initial change, I was assuming we would analyze System.IO.Pipelines, and assuming it is clean, we mark it as "IsTrimmable".
like this: System.Private.DataContractSerialization.csproj
That one is part of the shared fx, so it gets trimmed today in a user's app 🙃. When we get to that assembly, that comment and line will go away and we will trim it as part of the build like every other shared fx library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per discussion with @eerhardt, the plan is to opt all assemblies in as suggested by @marek-safar - and there's a new condition that we can use to opt out per project, should we need to.
By following the existing pattern for AssemblyMetadata like "Serviceable" and "PreferInbox", the attribute will be placed in src and ref assemblies, and also in assemblies targeting netstandard/netcoreapp/netfx. We need to include it for netstandard/netcoreapp because plenty of OOB assemblies build for those targets. Including the attributes in netfx assemblies shouldn't cause any issues since there are no common scenarios where an app targeting net6.0 references one of our netfx assemblies. I think it makes sense to be consistent with existing attributes on this, but @marek-safar if you prefer I could also disable it for netfx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and ref assemblies
Are ref assemblies ever trimmed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to be consistent with existing attributes on this, but @marek-safar if you prefer I could also disable it for netfx.
I'm not against it, just wanted to be more cautious for netfx to not break bad code which could, for example, read only the last AssemblyMetadata but the chance is low.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are ref assemblies ever trimmed?
No. But they are also never "serviced", and yet we are marking them with "Serviceable" assembly metadata. We should consistently apply these attributes across the assemblies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. But they are also never "serviced", and yet we are marking them with "Serviceable" assembly metadata. We should consistently apply these attributes across the assemblies.
FWIW starting .NET 5, we can now service the ref pack, we try to avoid it but we added support to be able to do it in case we need it, but I'm fine with adding IsTrimmable to them for consistency.
Tagging subscribers to this area: @safern, @ViktorHofer Issue DetailsThis will opt them into trimming with the behavior described at https://github.com/mono/linker/blob/main/docs/design/trimmed-assemblies.md#assemblymetadataistrimmable-true. The linker part of this change is happening in dotnet/linker#1839. @marek-safar @eerhardt @vitek-karas
|
Tagging subscribers to 'size-reduction': @eerhardt, @SamMonoRT, @marek-safar, @tannergooding, @CoffeeFlux Issue DetailsThis will opt them into trimming with the behavior described at https://github.com/mono/linker/blob/main/docs/design/trimmed-assemblies.md#assemblymetadataistrimmable-true. The linker part of this change is happening in dotnet/linker#1839. @marek-safar @eerhardt @vitek-karas
|
Will this resolve dotnet/aspnetcore#27782 by itself? Or will we need more work to fix that? |
If we opt System.IO.Pipelines in as part of the change, there shouldn't be any more work in runtime or aspnet, but we'll need to wait for dotnet/linker#1839 to flow, and for the upcoming SDK change that will include an update to use the new options. |
src/libraries/System.IO.Pipelines/src/System.IO.Pipelines.csproj
Outdated
Show resolved
Hide resolved
A project just needs to set <SetIsTrimmable>false</SetIsTrimmable>, and it won't get the trimmable metadata. I also got rid of the SkipFrameworkAssemblyMetadata check since I don't think the IsTrimmable metadata should be tied to whether we are building a framework assembly, and this property was unused as far as I could tell.
e90a6fb
to
d03327e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sbomer.
Note, after this gets plumbed all the way through, we should be able to remove the StartsWith('Microsoft.Extensions.')
workaround in the blazor SDK (cc @pranavkm @captainsafia)
@@ -83,7 +86,7 @@ | |||
</AssemblyAttribute> | |||
|
|||
<AssemblyAttribute Include="System.Reflection.AssemblyMetadata" | |||
Condition="'$(SkipFrameworkAssemblyMetadata)' != 'true' and '@(AssemblyMetadata)' != ''"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why are we removing the SkipFrameworkAssemblyMetadata
condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't appear to be used.
https://github.com/dotnet/runtime/search?q=SkipFrameworkAssemblyMetadata
Also, I'm assuming it is for the case where IsTrimmable
should be generated for the assembly, but someone adds SkipFrameworkAssemblyMetadata
to the project. That would block IsTrimmable
from getting generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup - see also the second commit message: d03327e
@@ -22,5 +22,6 @@ | |||
|
|||
[assembly: AssemblyMetadata("Serviceable", "True")] | |||
[assembly: AssemblyMetadata(".NETFrameworkAssembly", "")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely unrelated to this PR, but it caught my eye... is this value still desired? Should the "Framework" piece be removed?
cc: @ericstj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These assemblies now opt into trimming using AssemblyMetadata: dotnet/runtime#48428. The SDK side of the change was made in dotnet/sdk#16094. For more context, see https://github.com/mono/linker/blob/main/docs/design/trimmed-assemblies.md#net-6.
[master] Update dependencies from dotnet/sdk - Coherency Updates: - Microsoft.NET.ILLink.Tasks: from 6.0.100-preview.2.21124.3 to 6.0.100-preview.2.21125.1 (parent: Microsoft.NET.Sdk) - Don't set IsTrimmable on netcoreapp in 6.0 These assemblies now opt into trimming using AssemblyMetadata: dotnet/runtime#48428. The SDK side of the change was made in dotnet/sdk#16094. For more context, see https://github.com/mono/linker/blob/main/docs/design/trimmed-assemblies.md#net-6.
This will opt them into trimming with the behavior described at https://github.com/mono/linker/blob/main/docs/design/trimmed-assemblies.md#assemblymetadataistrimmable-true.
The linker part of this change is happening in dotnet/linker#1839.
@marek-safar @eerhardt @vitek-karas