Skip to content

Reduce allocations in AnalyzerDriver.TryExecuteSymbolEndActions#79855

Merged
ToddGrun merged 2 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/TryExecuteSymbolEndActions_Allocations
Sep 11, 2025
Merged

Reduce allocations in AnalyzerDriver.TryExecuteSymbolEndActions#79855
ToddGrun merged 2 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/TryExecuteSymbolEndActions_Allocations

Conversation

@ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Aug 8, 2025

The completedAnalyzers array was using an ArrayBuilder and would commonly exceed the ArrayBuilder reuse size threshold, preventing array reuse. Instead, just use an IA.Builder pool directly for pooling purposes.

This allocation was showing up as about 0.6% of allocations during completion scenarios in the razor cohosting speedometer test.

Test insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/662551

Numbers from the speedometer run with this change look good, DiagnosticAnalyzer[] allocations went from about 1.0% of total allocations down to about 0.1%.

image

The completedAnalyzers array was using an ArrayBuilder and would commonly exceed the ArrayBuilder reuse size threshold, preventing array reuse. Instead, just use an IA.Builder pool directly for pooling purposes.

This allocation was showing up as abou 0.6% of allocations during completion scenarios in the razor cohosting speedometer test.
@ToddGrun ToddGrun changed the title *** WIP: Reduce allocations in AnalyzerDriver.TryExecuteSymbolEndActions Reduce allocations in AnalyzerDriver.TryExecuteSymbolEndActions Aug 19, 2025
@ToddGrun ToddGrun marked this pull request as ready for review August 19, 2025 14:53
@ToddGrun ToddGrun requested a review from a team as a code owner August 19, 2025 14:53
@ToddGrun
Copy link
Contributor Author

@dotnet/roslyn-compiler -- This is ready for review now.

@ToddGrun
Copy link
Contributor Author

@dotnet/roslyn-compiler for 2nd review

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Sep 8, 2025

@dotnet/roslyn-compiler -- still need a 2nd review

1 similar comment
@ToddGrun
Copy link
Contributor Author

@dotnet/roslyn-compiler -- still need a 2nd review


var success = true;
var completedAnalyzers = ArrayBuilder<DiagnosticAnalyzer>.GetInstance();
var completedAnalyzers = s_diagnosticAnalyzerPool.Allocate();
Copy link
Contributor

@AlekseyTs AlekseyTs Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var

Please spell out the type since it is no longer mentioned on the right #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we actually changing the type used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was changing the type, but I'll go ahead and make the change that you requested from the other PR to use an ObjectPool<ArrayBuilder> even though I'm definitely not a fan.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 1)

@ToddGrun
Copy link
Contributor Author

LGTM (commit 1)

@AlekseyTs -- Does commit 2 work for you?

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 2)

@ToddGrun ToddGrun merged commit d12119a into dotnet:main Sep 11, 2025
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Sep 11, 2025
333fred added a commit to 333fred/roslyn that referenced this pull request Sep 11, 2025
* upstream/main: (233 commits)
  Extensions: add SyntaxGenerator support and AssociatedExtensionImplementation API (dotnet#80170)
  Fix error when hoisting a non-ref call (dotnet#80138)
  Ensure that refkinds are rewritten for complex methods (dotnet#79916)
  Revert
  Do not go through the workspace to access services
  DefiniteAssignmentPass.MarkFieldsUsed - avoid infinite recursion due to generic substitution (dotnet#80135)
  Reduce allocations in AnalyzerDriver.TryExecuteSymbolEndActions (dotnet#79855)
  RefSafetyAnalysis: Fix handling of nested deconstruction utilizing modern extensions (dotnet#80231)
  Extensions: adjust rewriting of anonymous type property symbols (dotnet#80211)
  Extensions: Move public APIs into INamedTypeSymbol (dotnet#80230)
  Extensions: improve error recovery in older language versions (dotnet#80206)
  Fall back to `dotnet exec` if apphost does not exist (dotnet#80153)
  Update dependencies from https://github.com/dotnet/dotnet build 282708 (dotnet#80228)
  Add a workaround for microsoft/vs-mef#620
  Revert "FailFast if the MEF composition is clearly broken"
  switch from windows combobox to visualstudio combobox (dotnet#80219)
  Update System.Text.Json in packages which use 4.12 Roslyn (dotnet#80197)
  add flags to unblock CI (dotnet#80222)
  Move static members to another type - qualifies static member references in the moved members (dotnet#80178)
  Fix broken link for C# 14 lambda parameter modifiers
  ...
@akhera99 akhera99 modified the milestones: Next, 18.0 P1, 18.0 P2 Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants