You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ILLinkTrimAssembly condition applies to NetCoreAppCurrent only #58343
The ILLinkTrimAssembly property is conditioned on NetCoreAppCurrent inbox assets only. Some packages contain both inbox and OOB assets. The illink optimization will be lost for net6.0 when NetCoreAppCurrent means net7.0 and new packages will be released.
@joperezr@stephentoub unrelated but curious, why do we only trim assemblies inside the shared framework?
Build time tradeoff - According to Add ILLink to the build corefx#17825 (comment), at the time the initial integration increased the local build time by 35%. We build a lot more libraries now - i.e. Microsoft.Extensions.*
If we think it is valuable for our OOB libraries to get trimmed before they are packaged, there are reasons to believe that libraries outside of dotnet/runtime would benefit as well. So at that point, it shouldn't be a dotnet/runtime build infrastructure feature, but instead a .NET SDK feature. That way it is fully supported by the tooling.
Do we think the benefits are going to out weigh the risk/cost? As you go up the stack, the amount of statically trimmable code decreases. If we have libraries with lots of "dead code" - we should just remove that dead code. At the shared framework (and also runtimepack) level, we can even trim the assemblies for OS-arch specific configurations as well. (However, note that idea has been rejected so far - see Run illink task with at the end of build #31712.).
The ILLinkTrimAssembly property is conditioned on NetCoreAppCurrent inbox assets only. Some packages contain both inbox and OOB assets. The illink optimization will be lost for net6.0 when NetCoreAppCurrent means net7.0 and new packages will be released.
I wanted to highlight @ericstj's comment here, just to ensure it isn't lost. Because it is super important w.r.t. "The illink optimization will be lost for net6.0 when NetCoreAppCurrent means net7.0 and new packages will be released.":
Folks were confident that we had better test coverage of the shared framework since that's what we were shipping at the time. We could broaden that scope but we'd probably want to make sure such a change had decent test coverage + auditing of the new assemblies it touched across all their supported frameworks.
We currently don't run any tests for "net6.0 when NetCoreAppCurrent means net7.0". So it is rather dangerous to be trimming these assemblies.
We currently don't run any tests for "net6.0 when NetCoreAppCurrent means net7.0". So it is rather dangerous to be trimming these assemblies.
Agreed, I'm very much concerned that we don't test non-current .NETCoreApp tfms, which is why I filed #54639. That said, isn't it even more dangerous to create an artificial difference between $(NetCoreAppCurrent) (linked) and previous .NETCoreApp assemblies (unlinked) as we only test $(NetCoreAppCurrent) which is linked?
Also, the moment we ship new packages (i.e. NET6), anyone who isn't on the very latest shared framework (including servicing releases) will suffer from performance regressions based on consuming unlinked assemblies. Are we fine with that?
Note that the actual set of libraries which are inbox and ship as part of packages is quite small:
System.Collections.Immutable
System.Diagnostics.DiagnosticSource
System.Formats.Asn1
System.Net.Http.Json
System.Reflection.Metadata
System.Runtime.CompilerServices.Unsafe
System.Text.Encoding.CodePages
System.Text.Encodings.Web
System.Text.Json
System.Threading.Channels
System.Threading.Tasks.Dataflow
I think we should at least trim all .NETCoreApp inbox assemblies. At the moment, only the "best applicable" $(NetCoreAppCurrent) asset is trimmed. As we produce our packages on a Windows leg, inbox libraries which are RID specific are only trimmed when targeting Windows. This means that even for $(NetCoreAppCurrent) assemblies, the linker optimization might be lost if the assembly targets a non Windows RID.
Let's fix #54639 and add non-current .NETCoreApp test configurations for the libraries in the list above. We should do that in the main branch and then back-port into release/6.0.
isn't it even more dangerous to create an artificial difference between $(NetCoreAppCurrent) (linked) and previous .NETCoreApp assemblies (unlinked) as we only test $(NetCoreAppCurrent) which is linked?
I wouldn't be able to say which is "more dangerous" without testing. Since we don't use the linker at all when in "library mode" against previous .NETCoreApp assemblies, I wouldn't put it as "safer" than any other scenario. Another thought is that leaving IL in an assembly typically works more often than taking IL out.
Also, the moment we ship new packages (i.e. NET6), anyone who isn't on the very latest shared framework (including servicing releases) will suffer from performance regressions based on consuming unlinked assemblies. Are we fine with that?
What kind of performance regressions are you referring to? In the above list, how many of those assemblies have enough dead code in them to actually cause any measurable regression?
On a separate note - in the scenario you list, those assemblies are no longer crossgen'd when they come from NuGet packages, which will cause an even greater performance regression than having a few KBs of dead IL.
I think we should at least trim all .NETCoreApp inbox assemblies. At the moment, only the "best applicable" $(NetCoreAppCurrent) asset is trimmed.
I agree with @ViktorHofer that with the library set above, we should just turn on trim to all netcoreapp configs (not just the best applicable). There is no testing concern there as we have our unit test coverage testing against the trimmed version of the library, so shipping an un-trimmed version as oob (not tested) that can replace the trimmed one (tested) doesn't sound great. We should consider what to do with regards to other TFMs and other libraries, and check perf impact, but I think that at least for .NET 6, it would be good to enable trimming for all netcoreappcurrent configs for the set that @ViktorHofer showed above.
Note, as @vitek-karas suggested offline, an alternative approach would be to not trim those libraries at all (the libraries that ship both inbox and OOB), even "the best applicable". If the concern is to be consistent, not trimming at all would make it consistent.
While that is true, if we are thinking about what do we want to ship in .NET 6, I'd be more comfortable with the approach of trimming always for those as opposed to not trimming. Reason being that we've been testing these assemblies trimmed for the whole product cycle, so seems a bit risky to change that this late.
True, I guess the uneasy feeling for that one is that we are only testing the linked asset, but shipping an un-linked that will be used if the package is consumed. My suggestion of fixing it and marking as the "important one" is mostly due to the fact that we are shipping assets we don't test in that case.
For 6.0 I would like us to enable trimming NetCoreAppCurrent inbox source assemblies but exclude PNSE assemblies: Don't trim PNSE assemblies and enable trimming for inbox assets on all .NETCoreApp versions #58345 (but change the $(TargetFrameworkIdentifier) condition to $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '$(NETCoreAppCurrentVersion)')) to only trim NetCoreAppCurrent.
Activity
stephentoub commentedon Aug 30, 2021
cc: @eerhardt
eerhardt commentedon Aug 30, 2021
It hasn't changed since it was first integrated into our build. See dotnet/corefx#17825 (comment).
Other reasons I can imagine:
@vitek-karas @marek-safar - any thoughts on this topic?
eerhardt commentedon Aug 30, 2021
I wanted to highlight @ericstj's comment here, just to ensure it isn't lost. Because it is super important w.r.t. "The illink optimization will be lost for net6.0 when NetCoreAppCurrent means net7.0 and new packages will be released.":
We currently don't run any tests for "net6.0 when NetCoreAppCurrent means net7.0". So it is rather dangerous to be trimming these assemblies.
ViktorHofer commentedon Aug 30, 2021
Agreed, I'm very much concerned that we don't test non-current .NETCoreApp tfms, which is why I filed #54639. That said, isn't it even more dangerous to create an artificial difference between
$(NetCoreAppCurrent)(linked) and previous .NETCoreApp assemblies (unlinked) as we only test$(NetCoreAppCurrent)which is linked?Also, the moment we ship new packages (i.e. NET6), anyone who isn't on the very latest shared framework (including servicing releases) will suffer from performance regressions based on consuming unlinked assemblies. Are we fine with that?
ViktorHofer commentedon Aug 30, 2021
Note that the actual set of libraries which are inbox and ship as part of packages is quite small:
I think we should at least trim all .NETCoreApp inbox assemblies. At the moment, only the "best applicable"
$(NetCoreAppCurrent)asset is trimmed. As we produce our packages on a Windows leg, inbox libraries which are RID specific are only trimmed when targeting Windows. This means that even for$(NetCoreAppCurrent)assemblies, the linker optimization might be lost if the assembly targets a non Windows RID.Let's fix #54639 and add non-current .NETCoreApp test configurations for the libraries in the list above. We should do that in the main branch and then back-port into release/6.0.
eerhardt commentedon Aug 30, 2021
I wouldn't be able to say which is "more dangerous" without testing. Since we don't use the linker at all when in "library mode" against previous .NETCoreApp assemblies, I wouldn't put it as "safer" than any other scenario. Another thought is that leaving IL in an assembly typically works more often than taking IL out.
What kind of performance regressions are you referring to? In the above list, how many of those assemblies have enough dead code in them to actually cause any measurable regression?
On a separate note - in the scenario you list, those assemblies are no longer crossgen'd when they come from NuGet packages, which will cause an even greater performance regression than having a few KBs of dead IL.
joperezr commentedon Aug 30, 2021
I agree with @ViktorHofer that with the library set above, we should just turn on trim to all netcoreapp configs (not just the best applicable). There is no testing concern there as we have our unit test coverage testing against the trimmed version of the library, so shipping an un-trimmed version as oob (not tested) that can replace the trimmed one (tested) doesn't sound great. We should consider what to do with regards to other TFMs and other libraries, and check perf impact, but I think that at least for .NET 6, it would be good to enable trimming for all netcoreappcurrent configs for the set that @ViktorHofer showed above.
eerhardt commentedon Aug 30, 2021
Note, as @vitek-karas suggested offline, an alternative approach would be to not trim those libraries at all (the libraries that ship both inbox and OOB), even "the best applicable". If the concern is to be consistent, not trimming at all would make it consistent.
joperezr commentedon Aug 30, 2021
While that is true, if we are thinking about what do we want to ship in .NET 6, I'd be more comfortable with the approach of trimming always for those as opposed to not trimming. Reason being that we've been testing these assemblies trimmed for the whole product cycle, so seems a bit risky to change that this late.
4 remaining items
joperezr commentedon Sep 7, 2021
True, I guess the uneasy feeling for that one is that we are only testing the linked asset, but shipping an un-linked that will be used if the package is consumed. My suggestion of fixing it and marking as the "important one" is mostly due to the fact that we are shipping assets we don't test in that case.
ericstj commentedon Sep 7, 2021
Let's make a call on this for 6.0.0 or move to 7.0.0.
ViktorHofer commentedon Sep 7, 2021
$(TargetFrameworkIdentifier)condition to$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '$(NETCoreAppCurrentVersion)'))to only trim NetCoreAppCurrent.I'm fine with doing the change (nr 2 is already in PR and just needs to be resurrected).
ericstj commentedon Sep 29, 2021
@ViktorHofer are you still planning to do something for 6.0 GA?
ViktorHofer commentedon Oct 26, 2021
This got fixed with #58345 for main.