-
Notifications
You must be signed in to change notification settings - Fork 231
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
Performance: UtilityAnalyzerBase calls GetSemanticModel for each SyntaxTree #6558
Comments
(off-topic from this issue) @martin-strecker-sonarsource from the POV of RS1030, should we use |
Not in general, but we should look for violations of RS1030. There are some use cases where you have no other option than to call sonar-dotnet/analyzers/src/SonarAnalyzer.Common/Helpers/SemanticModelHelper.cs Lines 25 to 36 in 543953b
|
We should definitely think about some RegisterSyntaxTree analyzer. If we call the semanticModel in 99% of the cases for such a rule, we are better off with using RegisterSemanticModel instead. The reason is that "SyntxTreeAction" gets called right after the AST is produced. Then the compiler does in parallel the binding (which takes a long time). If you call the semanticModel, you will have to wait until the binding is finished basically blocking the thread. I'm not really sure if the above is exactly right as the documentation doesn't tell about these specifics. The best I could find was this: https://github.com/dotnet/roslyn/blob/main/docs/analyzers/Analyzer%20Actions%20Semantics.md |
On Akka.Net, I did not see any change in performance, the semantic models are most likely cached as they are queried by different rules of the same analysis: |
Results for lucenenet - small improvement After |
Reopened |
UtilityAnalyzerBase
callsCompilation.GetSematicModel(syntaxTree)
heresonar-dotnet/analyzers/src/SonarAnalyzer.Common/Rules/Utilities/UtilityAnalyzerBase.cs
Lines 98 to 100 in f6a6857
This is such a big performance issue that the Roslyn team wrote an analyzer RS1030 to flag its use. We should consider looking for a better approach as described by the message of that rule:
dotnet/roslyn-analyzers#3114 (comment)
The text was updated successfully, but these errors were encountered: