Skip to content

Conversation

@ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Sep 8, 2023

This shows up as 15% of CPU in the code analysis process in a profile provided by DavidW where semantic token requests are performing poorly.

Roslyn classification walks down the tree, finding AssignmentExpressionSyntax nodes and performing semantic binding on the nodes (expensive).

Two optimizations to short-circuit before performing the binding: 1) Per Cyrus, this operation doesn't need to occur on simple assignments (the most common case of AssignmentExpressionSyntax nodes) 2) Check whether the requested range intersects the location where the classification would actually be reported.

This shows up as 15% of CPU in the code analysis process in a profile provided by DavidW where semantic token requests are performing poorly.

Roslyn classification walks down the tree, finding AssignmentExpressionSyntax nodes and performing semantic binding on the nodes (expensive).

Two optimizations to short-circuit before performing the binding:
1) Per Cyrus, this operation doesn't need to occur on simple assignments (the most common case of AssignmentExpressionSyntax nodes)
2) Check whether the requested range intersects the location where the classification would actually be reported.
@ToddGrun ToddGrun requested a review from a team as a code owner September 8, 2023 22:06
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 8, 2023
@ToddGrun
Copy link
Contributor Author

ToddGrun commented Sep 8, 2023

image

Dim symbolInfo = semanticModel.GetSymbolInfo(syntax, cancellationToken)
If TypeOf symbolInfo.Symbol Is IMethodSymbol AndAlso
DirectCast(symbolInfo.Symbol, IMethodSymbol).MethodKind = MethodKind.UserDefinedOperator Then
If (operatorSpan.IsEmpty OrElse Not operatorSpan.IntersectsWith(textSpan)) Then
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
If (operatorSpan.IsEmpty OrElse Not operatorSpan.IntersectsWith(textSpan)) Then
If operatorSpan.IsEmpty OrElse Not operatorSpan.IntersectsWith(textSpan) Then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

C# habits die hard

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bah, it doesn't look like this change was pushed before merged. Will create a small PR with just that.

@ToddGrun ToddGrun merged commit 8b5ee45 into dotnet:main Sep 9, 2023
@ghost ghost added this to the Next milestone Sep 9, 2023
@Cosifne Cosifne modified the milestones: Next, 17.8 P3 Sep 25, 2023
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.

Perf: OperatorOverloadSyntaxClassifier unnecessarily realizes semantic model for certain nodes

4 participants