Skip to content

Commit

Permalink
Reduce time spent in ConflictResolver.Session.GetNodesOrTokensToCheck…
Browse files Browse the repository at this point in the history
…ForConflicts (#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.
  • Loading branch information
ToddGrun authored Jun 25, 2024
1 parent 778d674 commit e79b9b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,12 @@ public RenameRewriter(RenameRewriterParameters parameters)

var isInConflictLambdaBody = false;
var lambdas = node.GetAncestorsOrThis(n => n is SimpleLambdaExpressionSyntax or ParenthesizedLambdaExpressionSyntax);
if (lambdas.Count() != 0)
foreach (var lambda in lambdas)
{
foreach (var lambda in lambdas)
if (_conflictLocations.Any(cf => cf.Contains(lambda.Span)))
{
if (_conflictLocations.Any(cf => cf.Contains(lambda.Span)))
{
isInConflictLambdaBody = true;
break;
}
isInConflictLambdaBody = true;
break;
}
}

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

var oldSpan = originalNode.Span;
var expandParameter = originalNode.GetAncestorsOrThis(n => n is SimpleLambdaExpressionSyntax or ParenthesizedLambdaExpressionSyntax).Count() == 0;
var expandParameter = !originalNode.GetAncestorsOrThis(n => n is SimpleLambdaExpressionSyntax or ParenthesizedLambdaExpressionSyntax).Any();

newNode = _simplificationService.Expand(newNode,
_speculativeModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,13 @@ private static bool IsConflictFreeChange(
private IEnumerable<(SyntaxNodeOrToken syntax, RenameActionAnnotation annotation)> GetNodesOrTokensToCheckForConflicts(
SyntaxNode syntaxRoot)
{
return syntaxRoot.DescendantNodesAndTokens(descendIntoTrivia: true)
.Where(_renameAnnotations.HasAnnotations<RenameActionAnnotation>)
.Select(s => (s, _renameAnnotations.GetAnnotations<RenameActionAnnotation>(s).Single()));
foreach (var nodeOrToken in syntaxRoot.GetAnnotatedNodesAndTokens(RenameAnnotation.Kind))
{
var annotation = _renameAnnotations.GetAnnotations<RenameActionAnnotation>(nodeOrToken).FirstOrDefault();

if (annotation != null)
yield return (nodeOrToken, annotation);
}
}

private async Task<bool> CheckForConflictAsync(
Expand Down

0 comments on commit e79b9b5

Please sign in to comment.