Skip to content

Commit e79b9b5

Browse files
authored
Reduce time spent in ConflictResolver.Session.GetNodesOrTokensToCheckForConflicts (#74101)
* Reduce time spent in ConflictResolver.Session.GetNodesOrTokensToCheckForConflicts This method previoulsy realized/walked the whole tree to try to find annotations to search for in it's AnnotationTable. Instead, use the GetAnnotatedNodesAndTokens to limit the search to only those areas of the tree that contain annotations. This showed up in a profile I took of a lightbulb session which showed the preview window.
1 parent 778d674 commit e79b9b5

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,12 @@ public RenameRewriter(RenameRewriterParameters parameters)
159159

160160
var isInConflictLambdaBody = false;
161161
var lambdas = node.GetAncestorsOrThis(n => n is SimpleLambdaExpressionSyntax or ParenthesizedLambdaExpressionSyntax);
162-
if (lambdas.Count() != 0)
162+
foreach (var lambda in lambdas)
163163
{
164-
foreach (var lambda in lambdas)
164+
if (_conflictLocations.Any(cf => cf.Contains(lambda.Span)))
165165
{
166-
if (_conflictLocations.Any(cf => cf.Contains(lambda.Span)))
167-
{
168-
isInConflictLambdaBody = true;
169-
break;
170-
}
166+
isInConflictLambdaBody = true;
167+
break;
171168
}
172169
}
173170

@@ -298,7 +295,7 @@ private SyntaxNode Complexify(SyntaxNode originalNode, SyntaxNode newNode)
298295
RoslynDebug.Assert(_speculativeModel != null, "expanding a syntax node which cannot be speculated?");
299296

300297
var oldSpan = originalNode.Span;
301-
var expandParameter = originalNode.GetAncestorsOrThis(n => n is SimpleLambdaExpressionSyntax or ParenthesizedLambdaExpressionSyntax).Count() == 0;
298+
var expandParameter = !originalNode.GetAncestorsOrThis(n => n is SimpleLambdaExpressionSyntax or ParenthesizedLambdaExpressionSyntax).Any();
302299

303300
newNode = _simplificationService.Expand(newNode,
304301
_speculativeModel,

src/Workspaces/Core/Portable/Rename/ConflictEngine/ConflictResolver.Session.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,13 @@ private static bool IsConflictFreeChange(
505505
private IEnumerable<(SyntaxNodeOrToken syntax, RenameActionAnnotation annotation)> GetNodesOrTokensToCheckForConflicts(
506506
SyntaxNode syntaxRoot)
507507
{
508-
return syntaxRoot.DescendantNodesAndTokens(descendIntoTrivia: true)
509-
.Where(_renameAnnotations.HasAnnotations<RenameActionAnnotation>)
510-
.Select(s => (s, _renameAnnotations.GetAnnotations<RenameActionAnnotation>(s).Single()));
508+
foreach (var nodeOrToken in syntaxRoot.GetAnnotatedNodesAndTokens(RenameAnnotation.Kind))
509+
{
510+
var annotation = _renameAnnotations.GetAnnotations<RenameActionAnnotation>(nodeOrToken).FirstOrDefault();
511+
512+
if (annotation != null)
513+
yield return (nodeOrToken, annotation);
514+
}
511515
}
512516

513517
private async Task<bool> CheckForConflictAsync(

0 commit comments

Comments
 (0)