Skip to content

Small optimization reducing repeated int.ToString calls in completion#82765

Open
ToddGrun wants to merge 2 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/SmallCompletionContextPositionCache
Open

Small optimization reducing repeated int.ToString calls in completion#82765
ToddGrun wants to merge 2 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/SmallCompletionContextPositionCache

Conversation

@ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Mar 15, 2026

SymbolCompletionItem.CreateWorker can be called thousands of times for each completion list, and in the scenarios I've tested, it passes in the same contextPosition for each call. We need this context position as a string to store in a properties collection, so previously the code always ToString'ed the position. This PR creates a simple single item cache that is used to commonly avoid this allocation.

Not a huge win, but it's 0.2% of total allocations in the trace I'm looking at.

image ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com//pull/82765)

SymbolCompletionItem.CreateWorker can be called thousands of times for each completion list, and in the scenarios I've tested, it passes in the same contextPosition for each call. We need this context position as a string to store in a properties collection, so previously the code always ToString'ed the position. This PR creates a simple single item cache that is used to commonly avoid this allocation.

Not a huge win, but it's 0.2% of total allocations in the trace I'm looking at.
@ToddGrun ToddGrun requested a review from a team as a code owner March 15, 2026 01:51
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