Skip to content

[release/11.0.2xx] Reduce CA1508 analysis cost for local-function calls - #56580

Merged
tannergooding merged 4 commits into
release/11.0.2xxfrom
backport/pr-56414-to-release/11.0.2xx
Nov 2, 2026
Merged

tannergooding merged 4 commits into
release/11.0.2xxfrom
backport/pr-56414-to-release/11.0.2xx

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #56414 to release/11.0.2xx

Related to #56412.

No servicing-approved label is recorded on this PR yet.

Customer Impact

  • Customer reported
  • Found internally

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

  • Yes
  • No

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.

tannergooding and others added 4 commits October 10, 2026 12:52
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>
@github-actions
github-actions Bot requested a review from a team as a code owner October 10, 2026 12:52
@github-actions github-actions Bot added the backport PR that has been backported to a servicing branch label Oct 10, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

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.

🟢 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 jeffhandley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good and I am supportive of the 11.0 servicing backport (post-GA). This addresses a substantial perf issue. /cc @artl93

@artl93 artl93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved, but best to preflight with the full context of analyzers since the list we reviewed recently was mostly backwards looking.

@tannergooding

tannergooding commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

@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 latest-all doesn't pick it up on upgrade. I'm not aware of any in this bucket currently.

@tannergooding
tannergooding merged commit be1e546 into release/11.0.2xx Nov 2, 2026
20 checks passed
@tannergooding
tannergooding deleted the backport/pr-56414-to-release/11.0.2xx branch November 2, 2026 18:17

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — 0ff1d159 Deployed Nov 2, 2026 by tannergooding via pre_activation #11621
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Microsoft.CodeAnalysis.NetAnalyzers backport PR that has been backported to a servicing branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants