-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Change SupportedPlatformData to use ImmutableArrays #76658
Change SupportedPlatformData to use ImmutableArrays #76658
Conversation
I'm looking at a different change to completion and the usage of IEnumerable and List in SupportedPlatformData was tripping it up. It's easy enough to just have it use ImmutableArrays instead. One concern would be additional allocations due to the IEnumerable -> ImmutableArray conversion. However, I don't think is an issue as the IEnumerable member is always passed in from a List except from AbstractSignatureHelpProvider. In that case, it's a constructed Linq Select/Concat expression, which is reused multiple times (and potentially enumerated multiple times in SupportedPlatformData). It's extremely likely that it's better to just realize that array once.
{ | ||
SupportedPlatformData? supportedPlatformData = null; | ||
if (invalidProjectMap != null) | ||
{ | ||
List<ProjectId>? invalidProjects = null; | ||
ArrayBuilder<ProjectId>? invalidProjects = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preference is the using form for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will change the other ones, I don't think this one can be changed as it doesn't own the builders.
@@ -299,7 +299,7 @@ private async Task<ImmutableArray<CompletionItem>> GetItemsAsync( | |||
if (relatedDocumentIds.IsEmpty) | |||
{ | |||
var itemsForCurrentDocument = await GetSymbolsAsync(completionContext, syntaxContext, position, options, cancellationToken).ConfigureAwait(false); | |||
return CreateItems(completionContext, itemsForCurrentDocument, _ => syntaxContext, invalidProjectMap: null, totalProjects: null); | |||
return CreateItems(completionContext, itemsForCurrentDocument, _ => syntaxContext, invalidProjectMap: null, totalProjects: ImmutableArray<ProjectId>.Empty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]
@@ -395,17 +400,17 @@ protected async Task<ImmutableArray<SymbolAndSelectionInfo>> TryGetSymbolsForCon | |||
/// <param name="symbolToContext">The symbols recommended in the active context.</param> | |||
/// <param name="linkedContextSymbolLists">The symbols recommended in linked documents</param> | |||
/// <returns>The list of projects each recommended symbol did NOT appear in.</returns> | |||
private static Dictionary<ISymbol, List<ProjectId>> FindSymbolsMissingInLinkedContexts( | |||
private static Dictionary<ISymbol, ArrayBuilder<ProjectId>> FindSymbolsMissingInLinkedContexts( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the consumer return these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
caller (line 317) owns the freeing of these builders
// We calculate the set of supported projects | ||
var invalidProjects = ArrayBuilder<ProjectId>.GetInstance(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the using form
@@ -277,7 +277,7 @@ symbolKeyItem.SymbolKey is not SymbolKey symbolKey || | |||
symbolKey = SymbolKey.Create(methodSymbol.OriginalDefinition, cancellationToken); | |||
} | |||
|
|||
var invalidProjectsForCurrentSymbol = new List<ProjectId>(); | |||
var invalidProjectsForCurrentSymbol = ArrayBuilder<ProjectId>.GetInstance(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here a well
I'm looking at a different change to completion and the usage of IEnumerable and List in SupportedPlatformData was tripping it up. It's easy enough to just have it use ImmutableArrays instead.
One concern would be additional allocations due to the IEnumerable -> ImmutableArray conversion. However, I don't think this is an issue as the IEnumerable member is always passed in from a List except from AbstractSignatureHelpProvider. In that case, it's a constructed Linq Select/Concat expression, which is reused multiple times (and potentially enumerated multiple times in SupportedPlatformData). It's extremely likely that it's better to just realize that array once.