Skip to content

Switch to balanced source generator execution in VSCode with refresh support#82330

Open
dibarbet wants to merge 2 commits intodotnet:mainfrom
dibarbet:balanced_vscode
Open

Switch to balanced source generator execution in VSCode with refresh support#82330
dibarbet wants to merge 2 commits intodotnet:mainfrom
dibarbet:balanced_vscode

Conversation

@dibarbet
Copy link
Member

@dibarbet dibarbet commented Feb 7, 2026

Client side PR: dotnet/vscode-csharp#8970

In VS we switched to balanced source gen execution a while back (#73618) to avoid perf issues with running generators on every keystroke. This ports the same change to VSCode.

Also added a small benchmark to compare perf between balanced and automatic. Balanced shows an improvement in cpu and allocations, even with an extremely simple generator.

Method TypingIterations ExecutionPreference Mean Error Gen 0 Gen 1 Gen 2 Allocated
TypeAndWaitForSourceGenerators 50 Automatic 243.8 ms NA - - - 11 MB
TypeAndWaitForSourceGenerators 50 Balanced 239.9 ms NA - - - 10 MB
TypeAndWaitForSourceGenerators 1000 Automatic 4,345.3 ms NA 2000.0000 1000.0000 - 216 MB
TypeAndWaitForSourceGenerators 1000 Balanced 3,897.0 ms NA 2000.0000 1000.0000 - 186 MB

@dibarbet dibarbet marked this pull request as ready for review February 7, 2026 04:41
@dibarbet dibarbet requested a review from a team as a code owner February 7, 2026 04:41
Description = "Controls when source generators are executed.",
Required = false,
// Balanced mode requires additional client side support (to trigger refreshes), so by default run in automatic to ensure tool scenarios without client support run generators.
DefaultValueFactory = _ => SourceGeneratorExecutionPreference.Automatic,
Copy link
Member Author

Choose a reason for hiding this comment

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

this seemed like a sane default if not provided to allow tools to work more easily. In VSCode we explicitly pass this and pick Balanced as the default there

DefaultValueFactory = _ => false,
};

var sourceGeneratorExecutionOption = new Option<SourceGeneratorExecutionPreference>("--sourceGeneratorExecutionPreference")
Copy link
Member Author

Choose a reason for hiding this comment

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

While we do have support live option changes, source generator execution preference does not support live modification, so this is passed in as a CLI arg.

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.

1 participant