-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Further cleanup and code reduction in analyzer driver. #76921
Conversation
In the scrolling speedometer test, the Roslyn CodeAnalysis process shows about 25% of CPU spent in this method. Of that, a surprising amount of it (11.2%) is spent in ImmutableSegmentedDictionary.TryGetValue. Debugging through this code, it appears this is because that is called O(m x n) times where m is the number of nodes to analyze and n is the number of items in groupedActions.GroupedActionsByAnalyzer. Instead, add a hook into GroupedAnalyzerActions to allow a mapping of kind -> analyzers. This can be used by executeNodeActionsByKind to get a much quicker way to determine whether the analyzer can contribute for the node in question. Only publishing this early so Cyrus can take a peek, as I still need to do a bit of debugging around these changes. Once Cyrus and I think the changes have merit, I will create a test insertion and publish the speedometer results once those are available. Only if all that goes well will I promote this PR out of draft mode.
Ignore that. I pinged the wrong PR. |
@@ -667,21 +667,18 @@ public void ExecuteAdditionalFileActions( | |||
private void ExecuteSyntaxNodeAction<TLanguageKindEnum>( | |||
SyntaxNodeAnalyzerAction<TLanguageKindEnum> syntaxNodeAction, | |||
SyntaxNode node, | |||
ISymbol containingSymbol, | |||
SemanticModel semanticModel, | |||
ExecutionData executionData, |
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.
this subsumes the common 4 pieces of data passed to all these methods.
node, containingSymbol, semanticModel, AnalyzerOptions, addDiagnostic, | ||
isSupportedDiagnostic, filterSpan, isGeneratedCode, cancellationToken); | ||
node, executionData.DeclaredSymbol, executionData.SemanticModel, AnalyzerOptions, addDiagnostic, | ||
isSupportedDiagnostic, executionData.FilterSpan, executionData.IsGeneratedCode, cancellationToken); |
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.
note: i could push the ExecutionData struct into these context objects to make them smaller as well if that's desired.
@@ -718,6 +712,13 @@ private void ExecuteOperationAction( | |||
cancellationToken); | |||
} | |||
|
|||
private readonly record struct ExecutionData( |
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.
The compiler's use of records is very restricted. It doesn't seem like we're making use of Equals
on this new type, so it should just be a regular struct.
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.
sure. i can do that. though it seems very verbose. :)
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.
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.
Sorry, it needs to be even more verbose ;-) We also don't do primary constructor captures.
This should have been flagged by an analyzer: dotnet/roslyn-analyzers#7138
Tagging @333fred to confirm
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.
what is the value in that verbosity? like... at least with records i can see not wanting the IL/metadata. But really this seems to be adding noise and hiding clear concepts in lots of code. :)
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.
note: the analyzer you are referencing disallows implicit capture. there is no implicit capture. it's all explicitly written to the explicit fields.
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 with review pass (iteration 59)
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 Thanks (iteration 61)
Followup to #76917
Primary change is making a new helper structure to capture many parameters taht are passed along to so many methods in these codepaths.