Skip to content

Use shared instances of NodeWriter classes#12362

Merged
ToddGrun merged 5 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/ReduceNodeWriterAllocations
Oct 21, 2025
Merged

Use shared instances of NodeWriter classes#12362
ToddGrun merged 5 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/ReduceNodeWriterAllocations

Conversation

@ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Oct 18, 2025

Several of the NodeWriter classes don't have state and can have a shared instance used among callers. These allocations aren't huge in the profiles, but the RazorEditingTests.ScrollingAndTypingInCohosting speedometer test shows about 3 MB of allocating these in the CodeAnalysis process.

Test insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/680496
Toolset run (commit 5): https://dev.azure.com/dnceng/internal/_build/results?buildId=2820760

*** Highlighted allocations of nodewriters previously (ignore the percentatges, as it's filtered to callstacks containing "NodeWriter")
image

Several of the NodeWriter classes don't have state and can have a shared instance used among callers. These allocations aren't huge in the profiles, but the RazorEditingTests.ScrollingAndTypingInCohosting speedometer test shows about 3 MB of allocating these in the CodeAnalysis process.
@ToddGrun ToddGrun requested a review from a team as a code owner October 18, 2025 00:04
2) Make classes that expose static Instance have private (or protected) constructors
3) Change from "{ get; => blah; }" syntax to "=> blah;" syntax.
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.

3 participants