Skip to content

Analyzer adversely affecting build performance #18618

Closed

Description

@roji

See dotnet/core#3663.

@Pilchie suggested:

I suspect that the advice will be to switch to using Operation analyzers (at least for the memberaccess and objectcreationexpression).
That should let you re-use some already bound info instead of your GetSymbolInfo calls causing the compiler to do a bunch of extra work to re-bind them.

Also look into whether we can/should exclude migration files.

/cc @bricelam

Activity

  1. Pilchie commented on Oct 28, 2019

    @Pilchie
    Member

    @agocke suggested that the overloads taking lambdas are causing a lot of the time. Not sure how much moving to IOperation would help if the underlying binding is already taking a long time. @mavasani - any ideas?

  2. mavasani commented on Oct 28, 2019

    @mavasani

    We have had some internal teams recently move from SyntaxNode/GetSymbolInfo based analyzer implementation to IOperation based implementation and they saw 4x-5x improvement in analyzer performance. I think it would be a good change to make regardless of whether or not it completely addresses the underlying performance concern of the analysis scenario.

  3. ajcvickers commented on Oct 28, 2019

    @ajcvickers
    Contributor

    Notes from triage:

    • Putting this in 3.1 to:
      • Ensure that generated code is being skipped
      • If the perf is still poor after skipping generated code, then consider also skipping migrations themselves. (It is possible these will be edited to use internal code, but that's not going to be common.)
    • Issue Revisit model-snapshot for perf #18620 covers the more general perf issue for big models and/or many migrations
  4. added this to the milestone on Oct 28, 2019
  5. bricelam commented on Oct 28, 2019

    @bricelam
    Contributor

    Confirmed that we generate already generate this in the snapshot and code behind:

    // <auto-generated />

    Maybe Roslyn doesn't handle self-closing tags? (or attributes for that matter)

  6. roji commented on Oct 28, 2019

    @roji
    MemberAuthor

    Will investigate what's going on tomorrow.

  7. Pilchie commented on Oct 28, 2019

    @Pilchie
    Member

    The roslyn code just looks at the start of the string, but the comment has to be the first thing in the file.

  8. Pilchie commented on Oct 28, 2019

    @Pilchie
    Member

    It also excludes some files by file name patterns, so it might be working already

  9. agocke commented on Oct 28, 2019

    @agocke
    Member

    So, modifying the analyzer could be useful, but the performance is still not great, even just building the code, because of the pattern of generated code.

    The key thing on the analyzer side is that we're somehow avoiding re-using symbols from binding, effectively causing us to bind twice. Obviously this slows things down even more, but the underlying binding is still unfortunate. Overall on the analyzer side I'd say:

    1. I agree they probably shouldn't be running on generated code. Something I can debug.
    2. An analyzer model that re-uses results from binding would be helpful. I don't know offhand what the best architecture to get this result is
  10. mavasani commented on Oct 28, 2019

    @mavasani

    RE: Generated code analysis

    Please ensure that analyzer explicitly configures generated code analysis mode by invoking AnalysisContext.ConfigureGeneratedCodeAnalysis in the Initialize callback.

  11. 28 remaining items

  12. modified the milestones: , 3.1.0 on Dec 2, 2019
  13. larrytamnjong commented on Oct 25, 2024

    @larrytamnjong

    Looking at this comment thread 5 years later and we're facing the same problem built time on our Asp.net core 8 wep API app takes almost 2 hours. We have approximately 80 migrations.

  14. roji commented on Oct 25, 2024

    @roji
    MemberAuthor

    @larrytamnjong we are not aware of any specific pending performance issues. How big are your migrations? Does everything run fast when you disable analyzers (see above)? If not, can you see which analyzers are taking how much time?

  15. larrytamnjong commented on Oct 25, 2024

    @larrytamnjong

    Thanks, @roji . We have 88 migrations in total. When I exclude them using the following configuration:

    <PropertyGroup> 
       <TargetFramework>net8.0</TargetFramework> 
       <DefaultItemExcludes Condition="'$(Configuration)' == 'Debug' ">$(DefaultItemExcludes);Migrations\\*.Designer.cs</DefaultItemExcludes> 
    </PropertyGroup>
    
    

    the project builds in just a few seconds. However, with migrations included, the build process becomes extremely slow—it can sometimes take over an hour and even freezes the computer. Disabling the analyzers hasn’t helped either.

    We have migration files that are over 4 Mb I don't know if that's normal.

  16. larrytamnjong commented on Oct 26, 2024

    @larrytamnjong

    @roji is there anything else you need me to provide to be able to remedy the situation or to improve the build time of out solution with the migrations.

  17. roji commented on Oct 26, 2024

    @roji
    MemberAuthor

    @larrytamnjong migration files over 4MB are generally not a good thing, and are very likely to cause pretty bad performance problems even regardless of any specific analyzer. What's the cumulative size of all of your migrations? What's the reason they're so big?

  18. larrytamnjong commented on Oct 26, 2024

    @larrytamnjong

    @roji I have 88 migrations, which are exactly 498 Mb in size. I don't know why they're so big. Each designer file contains migrations from all the previous migrations I don't know if that's what's causing the huge size. The migration files themselves are small a few kb but the designer files are very heavy some are reaching 6Mb

  19. roji commented on Oct 27, 2024

    @roji
    MemberAuthor

    @larrytamnjong then I suggest you take a look inside and understand what it is that's causing the size; for example, you may be using HasData() to seed huge data, which is very much discouraged. Having such huge migration source files is definitely not normal, and will likely affect your project in negative ways regardless of analyzers.

  20. larrytamnjong commented on Oct 27, 2024

    @larrytamnjong

    Thanks @roji we are actually using HasData to seed huge data I didn't figure this could be causing the issue. I'm confused about how to fix this considering the fact we already have migrations in production. Do you have any recommendations?

  21. roji commented on Oct 27, 2024

    @roji
    MemberAuthor

    FWIW the problems around using HasData with huge data is called out in the docs. Going forward, the simplest would probably be to reset your migrations, starting again from scratch without HasData. Otherwise, you can manually modify the migration files to remove all HasData.

  22. larrytamnjong commented on Oct 27, 2024

    @larrytamnjong
  23. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions