Repository navigation
[release/11.0.2xx] Reduce CA1508 analysis cost for local-function calls - #56580
Conversation
Trim unrelated caller state for safe direct local-function calls and skip enclosing CA1508 analysis when only nested functions have candidates. Preserve reachable aliases and fall back to full state when indirect effects cannot be ruled out. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reuse complete per-CFG referenced-member summaries across static local-function graphs; preserve aliases to static object roots when trimming would be unsafe. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟢 Approval recommended
It matches the reviewed source change, includes focused regression coverage, and release-branch CI passed.
0 open findings
What changed in this PR
Backports the approved CA1508 performance optimization to .NET 11 servicing.
Changes:
- Trims safe local-function flow state while preserving captures and aliases.
- Bounds and caches nested/static local-function scans.
- Adds diagnostic-correctness and deterministic performance regression tests.
| File | Description |
|---|---|
DisposeObjectsBeforeLosingScopeTests.cs |
Tests disposal through local-function callbacks. |
AvoidDeadConditionalCode_ValueContentAnalysis.cs |
Adds value-flow, aliasing, and scan-caching tests. |
AvoidDeadConditionalCode_NullAnalysis.cs |
Tests unrelated reference aliases. |
DataFlowOperationVisitor.cs |
Propagates trimmed-state metadata. |
AnalysisEntityDataFlowOperationVisitor.cs |
Implements safe trimming and cached scans. |
PointsToAnalysis.PointsToDataFlowOperationVisitor.cs |
Adapts points-to analysis to trimming metadata. |
GlobalFlowStateDataFlowOperationVisitor.cs |
Preserves full global-flow state behavior. |
DisposeAnalysis.DisposeDataFlowOperationVisitor.cs |
Propagates trimming metadata during disposal analysis. |
CopyAnalysis.CopyDataFlowOperationVisitor.cs |
Adapts copy analysis to trimming metadata. |
AvoidDeadConditionalCode.cs |
Excludes nested functions from enclosing candidate scans. |
🧠 Review effort: Balanced
jeffhandley
left a comment
There was a problem hiding this comment.
Looks good and I am supportive of the 11.0 servicing backport (post-GA). This addresses a substantial perf issue. /cc @artl93
artl93
left a comment
There was a problem hiding this comment.
Approved, but best to preflight with the full context of analyzers since the list we reviewed recently was mostly backwards looking.
|
@artl93, @jeffhandley for backports to 11.0, we only plan on things that are effectively "bug fix" level things. That is, it should be things like this where we are significantly improving the perf/UX or where we are fixing false-positives. It should not include anything that introduces new warnings/errors, especially not on by default. We could separately talk about introducing new off by default analyzers, but they would need to have their own opt-in so that existing |
Backport of #56414 to
release/11.0.2xxRelated to #56412.
No
servicing-approvedlabel is recorded on this PR yet.Customer Impact
In a project-scale reproduction, CA1508 accounted for 162.765 analyzer-seconds out of 187.173 aggregate core-project analyzer-seconds. Local-function calls repeatedly cloned and reanalyzed unrelated caller state, while nested functions could also be scanned as part of the enclosing method. This backport reduces that avoidable analyzer work for safe direct local-function calls and bounded static-local-function graphs.
Regression
This is an analyzer performance change intended to preserve diagnostics. State is trimmed only when safe; uncertain indirect effects retain the full-state analysis. The backport adds deterministic coverage for local-function state, aliases, cached scans, and nested-function handling.
Testing
The source PR's full CI passed. The release-branch pipeline for this backport is still running; release-branch test results are pending.
Risk
The production change is limited to analyzer flow-state processing and CA1508 candidate scanning. It does not change public APIs or diagnostic rules. Conservative fallbacks preserve full analysis where trimming safety cannot be established.
Note
This PR description was drafted with GitHub Copilot.