-
Notifications
You must be signed in to change notification settings - Fork 459
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
Meta analyzer to flag use of Compilation.GetSemanticModel inside diagnostic analyzers #3114
Comments
Tagging @Evangelink |
So, what is the replacement for an analyzer that actually does need to access symbol info to report accurate diagnostic? |
Diagnostic description in error list, when expanded, should give the info: roslyn-analyzers/src/Microsoft.CodeAnalysis.Analyzers/Core/CodeAnalysisDiagnosticsResources.resx Line 395 in 8bc7b0b
|
In general, it is always better performance wise to switch to RegisterOperationAction for semantic analysis of executable code and RegisterSymbolAction for semantic analysis of symbols and non-executable parts of the code. |
Got it. Thanks! |
We have seen tons of performance issues in sub-optimally written analyzers that end up creating completely new semantic models by invoking
Compilation.GetSemanticModel
. This leads the compiler to rebind the entire file, and doing it multiple times (say with SyntaxNode callbacks) can be a performance hog. For example, #2576 identified this can lead a 4x-5x slowdown. With nullability flow analysis in place inside the compiler, this can be even worse.We should write an analyzer that flags use of this API inside a diagnostic analyzer. Implementation of this analyzer should potentially be a sub-type of DiagnosticAnalyzerCorrectnessAnalyzer.
The text was updated successfully, but these errors were encountered: