-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
This method showed up in a customer profile, and I was able to reproduce locally.
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in commit 2
Done with review pass (commit 1) |
@AlekseyTs -- any remaining concerns? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 2)
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 ***
*** new memory allocations ***