Skip to content

VSTHRD002 and VSTHRD010 - Performance issues? #1526

@jirikanda

Description

@jirikanda

I would like to share my observation regarding build performance when using the VSTHRD002UseJtfRunAnalyzer and VSTHRD010MainThreadUsageAnalyzer.

Observation

We observe that the build takes significantly longer than expected in a project that uses:

  • Microsoft.VisualStudio.Threading.Analyzers
  • .NET 10
  • EF Core 10 with Code Migrations.

Build duration comparison (with analyzers vs. no analyzers):

dotnet build~58 seconds.
dotnet build -p:RunAnalyzers=false~10 seconds.

Analyzer timing from MSBuild.exe /v:d /p:reportanalyzer=true shows

Time (s)    %   Analyzer
  668,239   99   Microsoft.VisualStudio.Threading.Analyzers.CSharp, Version=17.14.15.42505, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  370,871   55      Microsoft.VisualStudio.Threading.Analyzers.VSTHRD010MainThreadUsageAnalyzer (VSTHRD010)
  290,486   43      Microsoft.VisualStudio.Threading.Analyzers.VSTHRD002UseJtfRunAnalyzer (VSTHRD002)
  3,736   <1      Microsoft.VisualStudio.Threading.Analyzers.VSTHRD103UseAsyncOptionAnalyzer (VSTHRD103)
  1,340   <1      Microsoft.VisualStudio.Threading.Analyzers.CSharpVSTHRD110ObserveResultOfAsyncCallsAnalyzer (VSTHRD110)
  1,252   <1      Microsoft.VisualStudio.Threading.Analyzers.CSharpVSTHRD012SpecifyJtfWhereAllowed (VSTHRD012)
  0,196   <1      Microsoft.VisualStudio.Threading.Analyzers.CSharpVSTHRD109AvoidAssertInAsyncMethodsAnalyzer (VSTHRD109)

The two analyzers (VSTHRD010 and VSTHRD002) account for the large majority of analyzer execution time.

Project details

  • The EF Core model contains ~100 model entities (SQL Server tables) in a Model project.
  • An Entity contains DbContext and 175 database migrations.
  • Each migration consist of two files:
    • the migration itself
    • and the "*.Designer.cs" file.
  • The designer files in project grow in time from ~60 kB to ~180 kB.
  • Total size of designer files in Entity project is 22,16 MB.
  • Total size of code files in Entity project is 22,86 MB.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions