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 IReferenceFinder.DetermineDocumentsToSearchAsync to not return an ImmutableArray #73093

Merged

Conversation

ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Apr 18, 2024

Rather, this method now utilizes a callback to be invoked with results. This prevents quite a few intermediary array allocations during find references invocations.

… an ImmutableArray

Rather, this method now encourages items that wish to be part of the result to invoke a callback with that result. This prevents quite a few intermediary array allocations during find references invocations.
@ToddGrun ToddGrun requested a review from a team as a code owner April 18, 2024 23:31
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 18, 2024
@@ -190,6 +190,8 @@ private async Task ProcessProjectAsync(Project project, ImmutableArray<ISymbol>
using var _2 = PooledDictionary<Document, MetadataUnifyingSymbolHashSet>.GetInstance(out var documentToSymbols);
try
{
using var _3 = ArrayBuilder<Document>.GetInstance(out var documents);
Copy link
Member

Choose a reason for hiding this comment

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

maybe doc semantics. call it documentsBuffer indicating it will be reset/cleared on iterations?

@@ -43,20 +46,18 @@ protected override bool CanFind(IMethodSymbol symbol)

var underlyingNamedType = GetUnderlyingNamedType(symbol.ReturnType);
Contract.ThrowIfNull(underlyingNamedType);
var documentsWithName = await FindDocumentsAsync(project, documents, cancellationToken, underlyingNamedType.Name).ConfigureAwait(false);
var documentsWithType = await FindDocumentsAsync(project, documents, underlyingNamedType.SpecialType.ToPredefinedType(), cancellationToken).ConfigureAwait(false);

using var _ = ArrayBuilder<Document>.GetInstance(out var result);
Copy link
Member

Choose a reason for hiding this comment

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

nit (and you're preserving logic, so up to you), but chaneg this to a pooled hashset. it was an array before to keep all the sigs the same. but now that this is callbac style, this can change.

using var _ = ArrayBuilder<Document>.GetInstance(out var result);
using var _ = PooledHashSet<Document>.GetInstance(out var result);
await FindDocumentsAsync(project, documents, static (doc, result) => result.Add(doc), result, cancellationToken, underlyingNamedType.Name).ConfigureAwait(false);
await FindDocumentsAsync(project, documents, underlyingNamedType.SpecialType.ToPredefinedType(), static (doc, result) => result.Add(doc), result, cancellationToken).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

nit. ont thing i've been thinking about is the repetition of things like static (doc, result) => result.Add(doc). Consider a protected static in the topmost type like Action<...> StandardAddCallback and reference those here. (may not work due to genercs).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went ahead and made that change (I like the idea, but these were the only ones I could find).

@ToddGrun ToddGrun enabled auto-merge (squash) April 19, 2024 04:37
@ToddGrun
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@ToddGrun ToddGrun merged commit 7c55f24 into dotnet:main Apr 19, 2024
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 19, 2024
ToddGrun added a commit to ToddGrun/roslyn that referenced this pull request Apr 20, 2024
…ations> created during find references invocations.

This is very similar to this PR (dotnet#73093) that did the same thing for ImmutableArray<Document> in this context.
ToddGrun added a commit that referenced this pull request Apr 20, 2024
…ations> created during find references invocations. (#73118)

Reduce allocations due to multiple levels of ImmutableArray<FinderLocations> created during find references invocations.

This is very similar to this PR (#73093) that did the same thing for ImmutableArray<Document> in this context.
@ToddGrun ToddGrun deleted the FewerIntermediateArraysDuringReferenceFindCalls branch April 21, 2024 15:28
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 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.

None yet

3 participants