-
Notifications
You must be signed in to change notification settings - Fork 229
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
Make UtilityAnalyzerBase stateless by removing properties #8221
Make UtilityAnalyzerBase stateless by removing properties #8221
Conversation
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Performance measurement with the analyzer runner, the CSVHelper project, and 4 runs of master(org) and PR (chg) each can be found here (internal only) Summary
Note: The absolute best run was run 5 of the changed solution, but wasn't included in the results:
|
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!
@@ -35,11 +35,11 @@ public abstract class AnalysisWarningAnalyzerBase : UtilityAnalyzerBase | |||
protected sealed override void Initialize(SonarAnalysisContext context) => | |||
context.RegisterCompilationAction(c => | |||
{ | |||
ReadParameters(c); | |||
if (IsAnalyzerEnabled && !RoslynHelper.IsRoslynCfgSupported(MinimalSupportedRoslynVersion)) // MsBuild 15 is bound with Roslyn 2.x, where Roslyn CFG is not available. | |||
var parameter = ReadParameters(c); |
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.
I think we need to use the plural here.
return new UtilityAnalyzerParameters( | ||
IsAnalyzerEnabled: true, | ||
IgnoreHeaderComments: sonarLintXml.IgnoreHeaderComments(language), | ||
AnalyzeGeneratedCode: sonarLintXml.AnalyzeGeneratedCode(language), |
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.
Just an idea, it's not required to do the change.
In order to avoid re-creating the parameters we can also provide a default value for analyzeGeneratedCode
and read it only when needed.
protected virtual UtilityAnalyzerParameters ReadParameters(SonarCompilationReportingContext context, bool? analyzeGeneratedCode = null)
...
AnalyzeGeneratedCode: analyzeGeneratedCode ?? sonarLintXml.AnalyzeGeneratedCode(language),
If we do this we can move the functionality in another class responsible only for creating these parameters.
In the long run, we might want to unify these analyzers in a single analyzer to be able to reduce some operations like subscribing and reading the parameters multiple times (reducing thread contention since multiple analyzers are waiting for the read to finish) or writing to multiple protobuf files.
Peach validation: Code colorization and references are working as expected. |
Fixes #7288
Re-open of #6902
Replaces #8218