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 due to multiple levels of ImmutableArray<FinderLocations> created during find references invocations. #73118

Merged

Conversation

ToddGrun
Copy link
Contributor

This is very similar to this PR (#73093) that did the same thing for ImmutableArray in this context. The general idea is to pass an action that the caller can use to process a result, rather than many levels of functions creating and returning ImmutableArrays.

…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 ToddGrun requested a review from a team as a code owner April 20, 2024 06:14
@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 20, 2024
foreach (var node in invocations)
{
var finderLocation = CreateFinderLocation(node, state, cancellationToken);
processResult(finderLocation, processResultData);
Copy link
Member

Choose a reason for hiding this comment

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

nit: i would be ok with this as a single line.

@@ -203,7 +203,7 @@ private async Task ProcessProjectAsync(Project project, ImmutableArray<ISymbol>
{
await finder.DetermineDocumentsToSearchAsync(
symbol, globalAliases, project, _documents,
static (doc, documents) => documents.Add(doc),
StandardCallbacks<Document>.AddToHashSet,
Copy link
Member

Choose a reason for hiding this comment

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

bute.

@@ -272,12 +272,15 @@ private async Task ProcessProjectAsync(Project project, ImmutableArray<ISymbol>
// just grab those once here and hold onto them for the lifetime of this call.
var cache = await FindReferenceCache.GetCacheAsync(document, cancellationToken).ConfigureAwait(false);

// scratch hashset to place results in. Populated/inspected/cleared in inner loop.
Copy link
Member

Choose a reason for hiding this comment

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

this does not look like a hashset :)

{
var group = await ReportGroupAsync(symbol, cancellationToken).ConfigureAwait(false);
await _progress.OnReferenceFoundAsync(group, symbol, location, cancellationToken).ConfigureAwait(false);
}

referencesForFinder.Clear();
Copy link
Member

Choose a reason for hiding this comment

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

it's interesting how close this pattern is to the pipewriting/reading stuff i just did. this might get cleaner (in the future) with a channel that is pulling off the items and reporting to them to the progress, while the main find is pushing into the channel.

// REVIEW: This looks to go to quite a bit of work to populate aliasReferences, but never uses it?
using var _3 = ArrayBuilder<FinderLocation>.GetInstance(out var aliasReferences);
await FindLocalAliasReferencesAsync(
typeReferences, methodSymbol, state, StandardCallbacks<FinderLocation>.AddToArrayBuilder, aliasReferences, 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.

i think i'm missing where aliasreferences ends up getting used.

Copy link
Member

Choose a reason for hiding this comment

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

oh. looks like you that was yoru comment as well :D. yes. seems like we can jsut remove this. if no tests break, we're good.

namedType, state, initialReferences, cancellationToken).ConfigureAwait(false);
namedType, state, StandardCallbacks<FinderLocation>.AddToArrayBuilder, initialReferences, cancellationToken).ConfigureAwait(false);

// call processResult on items in initialReferences
Copy link
Member

Choose a reason for hiding this comment

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

comment needs fleshing out. maybe like: these shoudl both be reported as normal results, but are also used later on to findmore results.

}

initialReferences.AddRange(await FindLocalAliasReferencesAsync(
initialReferences, symbol, state, cancellationToken).ConfigureAwait(false));
// call processResult on items in initialReferences
Copy link
Member

Choose a reason for hiding this comment

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

same comment.

},
(state, property, symbol, processResult, processResultData, cancellationToken),
options with { AssociatePropertyReferencesWithSpecificAccessor = false },
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.

this broke me. i assume if tests pass we're good :)

data.processResult(loc, data.processResultData);
},
processResultData: (options, state, symbol, cancellationToken, self: this, processResult, processResultData),
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.

this broke me. i assume if tests pass we're good :)

if (useResult)
data.processResult(loc, data.processResultData);
},
processResultData: (options, state, symbol, cancellationToken, self: this, processResult, processResultData),
Copy link
Member

Choose a reason for hiding this comment

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

can you put 'this' at the front.

Copy link
Member

Choose a reason for hiding this comment

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

and cancellationToken at the end? keep the rest as much in order as the signature of the containing method.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

signing off. LGTM. And i know the test coverage is very good here, so no concerns.

Mostly stylistic PR feedback
@ToddGrun ToddGrun merged commit 7d920a1 into dotnet:main Apr 20, 2024
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 20, 2024
@CyrusNajmabadi
Copy link
Member

Thanks for teh stylistic changes :)

@ToddGrun ToddGrun deleted the ReduceReferenceFindingFinderLocationAllocations 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.

3 participants