Reduce allocations in AnalyzerDriver.TryExecuteSymbolEndActions#79855
Merged
ToddGrun merged 2 commits intodotnet:mainfrom Sep 11, 2025
Merged
Conversation
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.
Contributor
Author
|
@dotnet/roslyn-compiler -- This is ready for review now. |
CyrusNajmabadi
approved these changes
Aug 26, 2025
Contributor
Author
|
@dotnet/roslyn-compiler for 2nd review |
Contributor
Author
|
@dotnet/roslyn-compiler -- still need a 2nd review |
1 similar comment
Contributor
Author
|
@dotnet/roslyn-compiler -- still need a 2nd review |
AlekseyTs
reviewed
Sep 10, 2025
|
|
||
| var success = true; | ||
| var completedAnalyzers = ArrayBuilder<DiagnosticAnalyzer>.GetInstance(); | ||
| var completedAnalyzers = s_diagnosticAnalyzerPool.Allocate(); |
Contributor
Contributor
There was a problem hiding this comment.
Are we actually changing the type used here?
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
Author
@AlekseyTs -- Does commit 2 work for you? |
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 ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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%.