Skip to content

Small allocation improvement to GreenNodeExtensions.WithAnnotationsGreen#12199

Merged
ToddGrun merged 1 commit intodotnet:mainfrom
ToddGrun:dev/toddgrun/WithAnnotationsGreen_allocations
Sep 9, 2025
Merged

Small allocation improvement to GreenNodeExtensions.WithAnnotationsGreen#12199
ToddGrun merged 1 commit intodotnet:mainfrom
ToddGrun:dev/toddgrun/WithAnnotationsGreen_allocations

Conversation

@ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Sep 8, 2025

The WithAnnotationsGreen method shows up as about 0.7% of allocations in the RoslynCodeAnalysisService process during the C# completions scenario in the razor cohosting completion test.

These changes should get rid of about 0.2% of that (The top two blue highlighted lines in the profile image).

image

…eenNode

The WithAnnotationsGreen method shows up as about 0.7% of allocations in the RoslynCodeAnalysisService process during the C# completions scenario in the razor cohosting completion test.

These changes should get rid of about 0.2% of that (The top two blue highlighted lines in the profile image).
@ToddGrun ToddGrun requested a review from a team as a code owner September 8, 2025 23:46
}

if (newAnnotations.Count == 0)
using var newAnnotations = new PooledArrayBuilder<SyntaxAnnotation>(annotations.Length);
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use a pooled hash set here instead?

Copy link
Member

Choose a reason for hiding this comment

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

I was going to ask the same question, but looking around it seems like the number of annotations is unlikely to ever be more than one. Unless I've misunderstood their use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely possible, but I figured these collections are usually small enough that an array might be the better choice, even with the Contains usage.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

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

From a quick search of the repo (and lack of understanding of the compiler), it seems like annotations are only used in half a dozen places, and could be replaced with strongly typed properties on each specific node syntax type. Worth logging a follow up?

TL;DR Annotations on Razor nodes could go the way of trivia.

@ToddGrun ToddGrun changed the title Small allocation improvement to GreenNodeExtensions.WithAnnotationsGreenNode Small allocation improvement to GreenNodeExtensions.WithAnnotationsGreen Sep 8, 2025
@ToddGrun
Copy link
Contributor Author

ToddGrun commented Sep 9, 2025

TL;DR Annotations on Razor nodes could go the way of trivia.

@DustinCampbell -- Is this on your list of items to purge?

@DustinCampbell
Copy link
Member

TL;DR Annotations on Razor nodes could go the way of trivia.

@DustinCampbell -- Is this on your list of items to purge?

Nope, and I think that's probably premature without further analysis.

@ToddGrun ToddGrun merged commit b2d602c into dotnet:main Sep 9, 2025
11 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Sep 9, 2025
@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants