Repository navigation
perf(analyzers): skip generated code in GenerateSerializationAttributesAnalyzer - #11384
Conversation
There was a problem hiding this comment.
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.
Code coverage
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 |
Part of #11362.
Problem
GenerateSerializationAttributesAnalyzer(ORLEANS0004) callsConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze)withoutReportDiagnostics. 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:
*.g.cs,*.designer.cs,*.generated.csand similar<auto-generated>commentgenerated_code = truein.editorconfig[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_ShouldNotTriggerDiagnosticpins 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 addingReportDiagnosticsinstead, which would change behaviour. As far as I can tell,Analyzehas 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=trueand are summed across threads. The setup is described in #11362.mainGenerateSerializationAttributesAnalyzer, rebuildGenerateSerializationAttributesAnalyzer, rebuild[GenerateSerializer]types, 64 grain interfaces, 433 grain methods.On this 24-core machine, total build and
CoreCompiletimes 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