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

Make AnalyzerActions a value type #40691

Merged
merged 13 commits into from
Jan 17, 2020

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented Jan 2, 2020

Fixes #39102

Reduces allocations during analysis of Roslyn.sln by many GB (6 GB, ~2.4%).

Baseline (c0c68fc):

Found 486295 diagnostics in 390792ms (248890727112 bytes allocated)

Updated (c0c68fc + 4c37d9a)

Found 486290 diagnostics in 391640ms (242634251728 bytes allocated)

@sharwell sharwell requested a review from a team as a code owner January 2, 2020 05:13
@333fred
Copy link
Member

333fred commented Jan 2, 2020

Done review pass (commit 7)

@sharwell sharwell changed the title Make AnalyzerActions a value type 🚧 Make AnalyzerActions a value type Jan 13, 2020
@sharwell sharwell changed the title 🚧 Make AnalyzerActions a value type Make AnalyzerActions a value type Jan 14, 2020
@sharwell
Copy link
Member Author

The initially observed regression turned out to be a bug in .NET Core: dotnet/runtime#1713.

@333fred
Copy link
Member

333fred commented Jan 16, 2020

Done review pass (commit 9)

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

LGTM (commit 13). @dotnet/roslyn-compiler (perhaps @agocke?) for a second review.

private ImmutableArray<OperationAnalyzerAction> _operationActions = ImmutableArray<OperationAnalyzerAction>.Empty;
public static readonly AnalyzerActions Empty = new AnalyzerActions(concurrent: false);

private ImmutableArray<CompilationStartAnalyzerAction> _compilationStartActions;
Copy link
Member

Choose a reason for hiding this comment

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

Can we just make these get-only autoprops?

Copy link
Member Author

Choose a reason for hiding this comment

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

The Add* methods mutate these fields in the current revision. A future change could make this struct immutable.

@@ -628,126 +628,187 @@ protected AnalyzerActions GetOrCreateAnalyzerActions(DiagnosticAnalyzer analyzer
// moves from an analyzer-centric model to an action-centric model. For example, the driver would need to stop asking
// if a particular analyzer can analyze syntax trees, and instead ask if any syntax tree actions are present. Also,
// the driver needs to apply all relevant actions rather then applying the actions of individual analyzers.
internal sealed class AnalyzerActions
internal struct AnalyzerActions
Copy link
Member

Choose a reason for hiding this comment

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

Can this be a readonly struct with IsEmpty and Concurrent moved to a With-ing pattern?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is still a mutable struct. It would be a decent size change to convert all the remaining mutation methods to immutable transforms.

@sharwell sharwell merged commit d6bc442 into dotnet:master Jan 17, 2020
@sharwell sharwell deleted the analyzer-actions-struct branch January 17, 2020 00:30
@sharwell sharwell added this to the 16.5.P3 milestone Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use a singleton for AnalyzerActions.Empty
4 participants