Skip to content

ILLinkTrimAssembly condition applies to NetCoreAppCurrent only #58343

Closed

Description

@ViktorHofer

Similar to what was being discussed in #54964.

See

<BinPlaceTargetFrameworks Include="$(NetCoreAppCurrent)-$(TargetOS)"
Condition="'$(BuildTargetFramework)' == '$(NetCoreAppCurrent)' or '$(BuildTargetFramework)' == ''">
<!-- enable trimming for any runtime project that's part of the shared framework and hasn't already set ILLinkTrimAssembly -->
<SetProperties Condition="'$(IsNETCoreAppSrc)' == 'true' and
'$(BinPlaceRuntime)' == 'true' and
'$(ILLinkTrimAssembly)' == ''">ILLinkTrimAssembly=true</SetProperties>
</BinPlaceTargetFrameworks>

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?

Activity

  1. added this to the 6.0.0 milestone on Aug 30, 2021
  2. ghost added
    untriaged
    on Aug 30, 2021
  3. removed
    untriaged
    on Aug 30, 2021
  4. stephentoub commented on Aug 30, 2021

    @stephentoub
    Member

    why do we only trim assemblies inside the shared framework?

    cc: @eerhardt

  5. eerhardt commented on Aug 30, 2021

    @eerhardt
    Member

    why do we only trim assemblies inside the shared framework?

    It hasn't changed since it was first integrated into our build. See dotnet/corefx#17825 (comment).

    Other reasons I can imagine:

    1. 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.*
    2. 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.
    3. 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.).

    @vitek-karas @marek-safar - any thoughts on this topic?

  6. eerhardt commented on Aug 30, 2021

    @eerhardt
    Member

    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.

  7. ViktorHofer commented on Aug 30, 2021

    @ViktorHofer
    MemberAuthor

    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?

  8. ViktorHofer commented on Aug 30, 2021

    @ViktorHofer
    MemberAuthor

    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.

  9. eerhardt commented on Aug 30, 2021

    @eerhardt
    Member

    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.

  10. joperezr commented on Aug 30, 2021

    @joperezr
    Member

    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.

  11. eerhardt commented on Aug 30, 2021

    @eerhardt
    Member

    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.

  12. joperezr commented on Aug 30, 2021

    @joperezr
    Member

    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.

  13. 4 remaining items

  14. joperezr commented on Sep 7, 2021

    @joperezr
    Member

    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.

  15. ericstj commented on Sep 7, 2021

    @ericstj
    Member

    Let's make a call on this for 6.0.0 or move to 7.0.0.

  16. ViktorHofer commented on Sep 7, 2021

    @ViktorHofer
    MemberAuthor
    1. 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.
    2. For 7.0 I think it makes sense to change this early to trim all inbox .NETCoreApp source assemblies and again exclude PNSEs: Don't trim PNSE assemblies and enable trimming for inbox assets on all .NETCoreApp versions #58345.

    I'm fine with doing the change (nr 2 is already in PR and just needs to be resurrected).

  17. ericstj commented on Sep 29, 2021

    @ericstj
    Member

    @ViktorHofer are you still planning to do something for 6.0 GA?

  18. modified the milestones: 6.0.0, 5.0.x, 7.0.0 on Oct 4, 2021
  19. ViktorHofer commented on Oct 26, 2021

    @ViktorHofer
    MemberAuthor

    This got fixed with #58345 for main.

  20. ghost locked as resolved and limited conversation to collaborators on Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions