Skip to content

Enable EnableTrimAnalyzer by default #21293

Closed

Description

@rolfbjarne

The idea is to set EnableTrimAnalyzers=true by default in our targets somewhere, so that customers get trimmer warnings by default in all configurations (even if they've disabled linking in some configurations).

There are a few thoughts here:

  • Our end goal is a fully trimmable world (100% trimmable won't happen, but we want to get as close as we can).
  • Mobile projects have been trimmed for many years, and as such mobile developers are more accustomed to trimming than desktop developers. Mobile code base is also often more trimmable than desktop code, for the same reason.
  • In theory we'd like the trim analyzers to only be enabled when the project trims in any configuration, but we can't reliably detect whether the trimmer is fully enabled (TrimMode=full) in any configuration, any logic to try to reason about this or compute an accurate value is bound to not work for someone, and as the complexity grows, it'll be harder to reason about when the trim analyzers are enabled.

So the proposal is to just set EnableTrimAnalyzers=true by default.

  • It's very simple.
  • It's easy to override in a customer's project (set EnableTrimAnalyzers=false).
  • It hopefully moves us towards a fully trimmable world.

In order to minimize impact, we could enable it early on for .NET 10 to capture feedback. If it turns out too disruptive, we can also back the change out again (which is easy, because it's a very simple change).

CC @jonathanpeppers

Activity

  1. added
    enhancement
    on Sep 24, 2024
  2. added this to the .NET 10 milestone on Sep 24, 2024
  3. dalexsoto commented on Sep 24, 2024

    @dalexsoto
    Member

    Agreed, we should enable this in the early previews of .NET 10 and get feedback if any 👍

  4. jonathanpeppers commented on Sep 24, 2024

    @jonathanpeppers
    Member

    For Android, I think we will have this change in .NET 9 RC 2 (if merged in time):

    So, the project template will have TrimMode=full for both Debug & Release, you get the same warnings on both, and we keep the default behavior of no trimming in Debug mode.

    A customer could remove TrimMode=full to get the behavior from .NET 8 or older.

  5. ivanpovazan commented on Sep 24, 2024

    @ivanpovazan
    Member
  6. vitek-karas commented on Sep 25, 2024

    @vitek-karas
    Member

    Do we set SuppressTrimAnalysisWarnings to true anywhere - that will effectively disable the analyzer even if EnableTrimAnalyzer is set to true since it will not produce any warnings due to the suppression.

  7. rolfbjarne commented on Sep 25, 2024

    @rolfbjarne
    MemberAuthor

    Do we set SuppressTrimAnalysisWarnings to true anywhere - that will effectively disable the analyzer even if EnableTrimAnalyzer is set to true since it will not produce any warnings due to the suppression.

    No we don't set SuppressTrimAnalysisWarnings (minor caveat: when building for NativeAOT, we set it to true when running ILLink, and then back to the user's value when running NativeAOT).

  8. self-assigned this
    on Sep 26, 2024
  9. added a commit that references this issue on Oct 1, 2024
    cceb557
  10. added a commit that references this issue on Oct 24, 2024
    51dae3b
  11. rolfbjarne commented on Oct 24, 2024

    @rolfbjarne
    MemberAuthor

    Fixed in .NET 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions