Skip to content

perf(analyzers): skip generated code in GenerateSerializationAttributesAnalyzer - #11384

Merged
ReubenBond merged 2 commits into
dotnet:mainfrom
koenbeuk:perf/analyzers-skip-generated-code
Oct 2, 2026
Merged

ReubenBond merged 2 commits into
dotnet:mainfrom
koenbeuk:perf/analyzers-skip-generated-code

Conversation

@koenbeuk

@koenbeuk koenbeuk commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Part of #11362.

Problem

GenerateSerializationAttributesAnalyzer (ORLEANS0004) calls ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze) without ReportDiagnostics. Roslyn therefore runs it over every class and struct declaration in generated code, then discards anything it reports there. In a project using Orleans, that includes every codec, copier, activator and invokable the Orleans code generator emits. For each declaration the analyzer binds every attribute through the semantic model to check for [GenerateSerializer].

Change

Use GeneratedCodeAnalysisFlags.None, as most other Orleans analyzers already do.

This applies to all code Roslyn classifies as generated, not just Orleans output:

  • the output of any source generator
  • files named *.g.cs, *.designer.cs, *.generated.cs and similar
  • files starting with an <auto-generated> comment
  • files marked generated_code = true in .editorconfig
  • types annotated with [GeneratedCode]

Diagnostics in all of these were already suppressed, so behaviour doesn't change. For example, a [GenerateSerializer] type with missing [Id] attributes in a protobuf- or NSwag-generated file got no ORLEANS0004 before, and still doesn't. The analyzer just no longer does work whose results were thrown away.

The new test SerializableClassInGeneratedCode_ShouldNotTriggerDiagnostic pins this behaviour, and it passes both before and after the change. If ORLEANS0004 is meant to fire in generated code, the right fix would be adding ReportDiagnostics instead, which would change behaviour. As far as I can tell, Analyze has been there since the analyzer was introduced and wasn't a deliberate choice.

Results

Synthetic grain-abstractions projects built against this branch and main (825aae7), measured in the same session with builds alternating between the two. Compiler server warm. Each value is the median of 7 runs; analyzer times come from -p:ReportAnalyzer=true and are summed across threads. The setup is described in #11362.

Workload main This PR Change
GenerateSerializationAttributesAnalyzer, rebuild Large 0.77s 0.41s −47%
GenerateSerializationAttributesAnalyzer, rebuild Small 0.23s 0.07s −70%
All Orleans analyzers, rebuild Large 2.32s 1.28s −45%
All Orleans analyzers, edit Large 2.02s 1.39s −32%
  • Large: 1,280 [GenerateSerializer] types, 64 grain interfaces, 433 grain methods.
  • Small: 160 types, 8 interfaces, 97 methods.

On this 24-core machine, total build and CoreCompile times show no measurable change (within ±5% run-to-run noise). The analyzers run in parallel with compilation, so the saving is CPU time rather than wall time. It should matter more on machines with fewer cores and in the IDE, where analyzers run continuously.

Measured on an AMD Ryzen 9 7900X (24 logical cores), Windows 11, .NET SDK 10.0.401.

Microsoft Reviewers: Open in CodeFlow

Copilot AI balanced review requested due to automatic review settings October 1, 2026 23:10
@koenbeuk
koenbeuk requested a review from ReubenBond as a code owner October 1, 2026 23:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused change preserves diagnostic behavior while avoiding unnecessary analyzer work and includes appropriate regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Improves analyzer performance by skipping generated code where ORLEANS0004 diagnostics were already suppressed.

Changes:

  • Disables generated-code analysis for GenerateSerializationAttributesAnalyzer.
  • Adds regression coverage confirming generated types produce no diagnostics.
File Description
src/​Orleans.Analyzers/​GenerateSerializationAttributesAnalyzer.cs Skips generated-code analysis.
test/​Orleans.Analyzers.Tests/​GenerateSerializationAttributesAnalyzerTest.cs Verifies generated code remains diagnostic-free.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 82.87% (115,443 / 139,303)
Branches 72.18% (33,504 / 46,419)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested 6bf11ad, not current main cc1a9ff.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

@ReubenBond
ReubenBond merged commit 642b460 into dotnet:main Oct 2, 2026
78 checks passed
This was referenced Oct 15, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants