Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce allocations in AbstractRecommendationServiceBasedCompletionProvider.GetSymbolsAsync #72157

Conversation

ToddGrun
Copy link
Contributor

This method was individually adding items to an ArrayBuilder without it's size configured. Potential issues with the current approach:

  1. There could be multiple resizes during the Add calls to get the array to it's final size
  2. Very likely the final capacity will exceed the array size, causing an allocation in generating the immutablearray.
  3. I was seeing a large number of items in these arrays, causing the array that does get created not to get freed back into the pool.

Instead, if we use the SelectAsArray method, we shouldn't have any extra allocations other than the resultant ImmutableArray.

Before allocations of type SymbolAndSelectionInfo[]:
image

After allocations of type SymbolAndSelectionInfo[]:
image

…vider.GetSymbolsAsync

This method was individually adding items to an ArrayBuilder without it's size configured. Potential issues with the current approach:

1) There could be multiple resizes during the Add calls to get the array to it's final size
2) Very likely the final capacity will exceed the array size, causing an allocation in generating the immutablearray.
3) I was seeing a large number of items in these arrays, causing the array that does get created not to get freed back into the pool.

Instead, if we use the SelectAsArray method, we shouldn't have any extra allocations other than the resultant ImmutableArray.
@ToddGrun ToddGrun requested a review from a team as a code owner February 16, 2024 23:40
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 16, 2024
var preselect = args.InferredTypes.Contains(GetSymbolType(symbol), SymbolEqualityComparer.Default) && !args.This.IsInstrinsic(symbol);
return new SymbolAndSelectionInfo(symbol, preselect);
},
(InferredTypes: inferredTypes, This: this));
Copy link
Member

Choose a reason for hiding this comment

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

nit: we often do @this or self.

@ToddGrun ToddGrun merged commit 25aa74d into dotnet:main Feb 19, 2024
27 checks passed
@ghost ghost added this to the Next milestone Feb 19, 2024
@jjonescz jjonescz modified the milestones: Next, 17.10 P2 Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants