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

Change SupportedPlatformData to use ImmutableArrays #76658

Merged

Conversation

ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Jan 7, 2025

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.

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.
@ToddGrun ToddGrun requested a review from a team as a code owner January 7, 2025 15:30
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 7, 2025
{
SupportedPlatformData? supportedPlatformData = null;
if (invalidProjectMap != null)
{
List<ProjectId>? invalidProjects = null;
ArrayBuilder<ProjectId>? invalidProjects = null;
Copy link
Member

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

Copy link
Contributor Author

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);
Copy link
Member

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(
Copy link
Member

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?

Copy link
Contributor Author

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();
Copy link
Member

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();
Copy link
Member

Choose a reason for hiding this comment

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

Here a well

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 VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants