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 Linq usage in SymbolDisplayVisitor.CreateAliasMap #73793

Merged
merged 2 commits into from
Jun 4, 2024

Conversation

ToddGrun
Copy link
Contributor

This method showed up in a customer profile, and I was able to reproduce locally. Local repro was open Roslyn.sln, wait for CPU to settle, in SyntaxTokenParser.cs, set caret inside cref="" value and invoke completion 10 times.

*** old memory allocations ***
image

*** new memory allocations ***
image

This method showed up in a customer profile, and I was able to reproduce locally.
@ToddGrun ToddGrun requested a review from a team as a code owner May 30, 2024 23:34
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 30, 2024
@@ -196,26 +196,39 @@ private void MinimallyQualify(INamedTypeSymbol symbol)
// NOTE(cyrusn): If we're currently in a block of usings, then we want to collect the
// aliases that are higher up than this block. Using aliases declared in a block of
// usings are not usable from within that same block.
var usingDirective = GetAncestorOrThis<UsingDirectiveSyntax>(startNode);
if (usingDirective != null)
while (startNode != null)
Copy link
Contributor

Choose a reason for hiding this comment

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

while (startNode != null)

It looks like, if we are not in in a using directive, we will traverse syntax all the way to the top in this loop, and then restart reversion from the beginning looking for a namespace declaration or a compilation unit node. Instead, we could also stop once we reached a BaseNamespaceDeclarationSyntax or CompilationUnitSyntax node. Then the next loop could continue from the current startNode instead of resetting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'd prefer to pass on this unless you feel strongly. It seems like the current code is authentic to the original implementation, and making the change that you suggested will complicate things slightly. If this method shows up in CPU profiles, then this suggestion sounds like a good idea to pursue.

@@ -196,26 +196,39 @@ private void MinimallyQualify(INamedTypeSymbol symbol)
// NOTE(cyrusn): If we're currently in a block of usings, then we want to collect the
// aliases that are higher up than this block. Using aliases declared in a block of
// usings are not usable from within that same block.
var usingDirective = GetAncestorOrThis<UsingDirectiveSyntax>(startNode);
if (usingDirective != null)
while (startNode != null)
Copy link
Contributor

@AlekseyTs AlekseyTs May 31, 2024

Choose a reason for hiding this comment

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

while (startNode != null)

It would be good to add a comment explaining that with this loop we are trying to get out of immediately enclosing using directive, if any. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 2

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1)

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Jun 3, 2024

@AlekseyTs -- any remaining concerns?

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers 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

4 participants