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

Refactor searching and reporting results in navto. #73249

Merged
merged 42 commits into from
Apr 27, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Apr 26, 2024

Local traces were showing a few sources of inefficiency when doing a NavTo search in a large solution (esp. durign the typing phase of writing the query):

  1. Cancellation was showing up quite high (sometimes more than 10% of the trace), due to high task fan-out, and cascading cancellation upwards. This changes us to no cancel by throwing, but just bailing out.
  2. High overhead of async calls during CPU heavy operations (searching). The main searching loop per file has become completely synchronous.
  3. stalls in searching while reporting results. Results could only be reported one at a time, and involved a cross process hop (to update the UI immediately). This has no changed to having the parallel search just push results to a channel (immediately allowing hte searching threads to continue). A dedicated task reads from the channel and reports it to the host. That task can send multiple items at a time when available.

@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 26, 2024
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review April 27, 2024 00:51
IEnumerable<T> items,
Func<T, Action<RoslynNavigateToItem>, CancellationToken, ValueTask> callback,
Func<ImmutableArray<RoslynNavigateToItem>, Task> onItemsFound,
CancellationToken cancellationToken)
Copy link
Member Author

Choose a reason for hiding this comment

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

this is hte core utility that all 3 nav-to search functions end up deferring to (search normal docs. search generated docs. search cached docs).

}, cancellationToken));
}

await Task.WhenAll(tasks).ConfigureAwait(false);
Copy link
Member Author

Choose a reason for hiding this comment

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

poor man's solution. I consider copying the runtime code and forking into roslyn. but it was complex enough i didn't want us to main that. And that code should not run here as this is the searching part, which should run in OOP on VS and on netcore for vscode anyways. (And it's the same logic as before, so no worse for any other client that was previously using hte old codepaths).

@CyrusNajmabadi CyrusNajmabadi requested a review from ToddGrun April 27, 2024 16:41
@CyrusNajmabadi
Copy link
Member Author

@ToddGrun for eyes.

nameMatcher.AddMatches(declaredSymbolInfo.Name, ref nameMatches.AsRef()) &&
containerMatcher?.AddMatches(declaredSymbolInfo.FullyQualifiedContainerName, ref containerMatches.AsRef()) != false)
{
if (cancellationToken.IsCancellationRequested)
Copy link
Contributor

Choose a reason for hiding this comment

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

if (cancellationToken.IsCancellationRequested)

nit: seems a bit overkill as this was checked earlier inside the loop

Copy link
Member Author

Choose a reason for hiding this comment

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

i kept this as addmatches is the expensive step. so this lets us bail after doing that check.

}

result.RemoveDuplicates();
return result.ToImmutableAndClear();
Copy link
Contributor

Choose a reason for hiding this comment

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

return result.ToImmutableAndClear();

Old code had a RemoveDuplicates call here. Just looking for validation that it wasn't necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

it wasn't necessary. this is for getting siblings, which alreadywill only be for unique projects.


var results = new ConcurrentSet<RoslynNavigateToItem>();
await SearchSingleDocumentAsync(
document, patternName, patternContainerOpt, declaredSymbolInfoKindsSet, t => results.Add(t), cancellationToken).ConfigureAwait(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

t => results.Add(t)

StandardCallbacks.AddToConcurrentSet?

Copy link
Contributor

Choose a reason for hiding this comment

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

would require passing around the set though

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah. don't care here :)

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit 34542bd into dotnet:main Apr 27, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the navToCleanup branch April 27, 2024 22:23
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Apr 27, 2024
@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