Skip to content

Don't create a new FormattingContext if there weren't any cleanup changes#12400

Merged
ToddGrun merged 2 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/DontCreateNewFormattingContextIfNoCleanupChanges
Oct 27, 2025
Merged

Don't create a new FormattingContext if there weren't any cleanup changes#12400
ToddGrun merged 2 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/DontCreateNewFormattingContextIfNoCleanupChanges

Conversation

@ToddGrun
Copy link
Contributor

FormattingContext.WithTextAsync shows up as the major CPU time user during onTypeFormatting, mostly due to it's eventual call to GeneratorRunResult.CreateAsync. This change just avoids one of those calls when not necessary.

@ToddGrun ToddGrun requested a review from a team as a code owner October 27, 2025 13:20
context.Logger?.LogSourceText("AfterCleanupDocument", cleanedText);

changedContext = await changedContext.WithTextAsync(cleanedText, cancellationToken).ConfigureAwait(false);
if (!cleanupChanges.IsEmpty)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Should probably move this a couple of lines higher, and just set cleanedText to formattedText if the changes are empty. There is no point calling WithChanges or logging the same content again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 2. I did consider originally doing that, but the WithChanges call short circuits if the IA is empty and I wasn't certain whether we wanted the logging call to always happen.

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.

2 participants