Skip to content
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

Revert "UtilityAnalyzer: Use RegisterCompilationStartAction" #7262

Merged
merged 5 commits into from
May 25, 2023

Conversation

mary-georgiou-sonarsource
Copy link
Contributor

This PR is reverting the change in the UtilityAnalyzerbase from this PR as it caused a regression (Note: this is not a full revert).

These are binlogs from the analysis of RavenDB without and with the revert.
tempsnip

@@ -31,9 +31,6 @@ public sealed class SonarCompilationStartAnalysisContext : SonarAnalysisContextB
public void RegisterSymbolAction(Action<SonarSymbolReportingContext> action, params SymbolKind[] symbolKinds) =>
Context.RegisterSymbolAction(x => action(new(AnalysisContext, x)), symbolKinds);

public void RegisterSemanticModelAction(Action<SonarSematicModelReportingContext> action) =>
Context.RegisterSemanticModelAction(x => action(new(AnalysisContext, x)));
Copy link
Contributor

Choose a reason for hiding this comment

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

The point in time given by RegisterSemanticModelAction is still right. The binding phase needs to be finished, before you can successfully query the semantic model for symbols.

First the parse phase, where source is tokenized and parsed into syntax that follows the language grammar. Second the declaration phase, where declarations from source and imported metadata are analyzed to form named symbols. Next the bind phase, where identifiers in the code are matched to symbols.

We need these compiler pipeline entry points. Please do not remove any (we should instead add more). The right thing to do is to ignore the sematic model passed in RegisterSemanticModelAction and create a new one with Compilation.GetSemanticModel(syntaxTree) in the action instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to revert the changes fully, as Only using a different semantic model will not fix the regression.
Calling ShouldGenerateMetrics from the SemanticModelAction is also slowing down the analysis significantly because it uses two concurrent collections inside.
The decision is to revert as close as possible to the original state in order to finish the sprint and make it to the next SQ release.

Making the change to SemanticModelAction makes sense, and at the same time it should be done as part of a proper sprint that focuses on it, so we can come up with the best-performing solution that is backed by a proper and thorough validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@martin-strecker-sonarsource I agree with @csaba-sagi-sonarsource - one thing I learned from this sprint is that even if the change makes absolute sense in code and in theory and maybe for some project sample used to test locally we still need to do a thorough performance validation as it might behave in an unexpected way (like in this case).

From my point of view - I would add an issue for this and I'd tackle it in the next hardening (as this one is coming to an end tomorrow and there will be not enough time to validate).

I'll also add a card to do a sprint dedicated to the hardening of the UtilityAnalyzers (specified and planned as this one had only scope to fix the regression). I think we can bring performance and cleanup value this way.

@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title [DRAFT] revert changes in utility base analyzer Revert "UtilityAnalyzer: Use RegisterCompilationStartAction" May 25, 2023
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban May 25, 2023
@mary-georgiou-sonarsource mary-georgiou-sonarsource marked this pull request as ready for review May 25, 2023 12:53
@sonarcloud
Copy link

sonarcloud bot commented May 25, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@costin-zaharia-sonarsource costin-zaharia-sonarsource left a comment

Choose a reason for hiding this comment

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

LGTM!

The initial idea was to reuse the semantic models created during analysis (RegisterSemanticModelAction) instead of recreating them, on the compilation end by calling Compilation.GetSemanticModel() method.

In theory, this sounds very good and it's the recommended way by the compiler team. It practice it did not work as expected.

What we observed is that it added too much pressure on the task pool (too much thread contention) and it had the reverse effect and slowed everything down.

@sonarcloud
Copy link

sonarcloud bot commented May 25, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban May 25, 2023
@mary-georgiou-sonarsource mary-georgiou-sonarsource added this to the 9.2 milestone May 25, 2023
@mary-georgiou-sonarsource mary-georgiou-sonarsource merged commit fd38a91 into master May 25, 2023
24 checks passed
Best Kanban automation moved this from Review approved to Validate Peach May 25, 2023
@mary-georgiou-sonarsource mary-georgiou-sonarsource deleted the mary/revert branch May 25, 2023 16:06
@pavel-mikula-sonarsource pavel-mikula-sonarsource moved this from Validate Peach to Done in Best Kanban May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Best Kanban
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants