Skip to content

Use the compiler-provided batch Fix All provider - #4229

Merged
AArnott merged 2 commits into
masterfrom
aarnott-compiler-batch-fixer
Oct 11, 2026
Merged

AArnott merged 2 commits into
masterfrom
aarnott-compiler-batch-fixer

Conversation

@AArnott

@AArnott AArnott commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

The custom batch fixer was introduced to work around early Roslyn reliability problems, and an earlier attempt to replace it raised memory concerns. This revisits that decision with current compiler implementations and paired memory measurements.

Fixes #4211

Approach

Delegate CustomFixAllProviders.BatchFixer to WellKnownFixAllProviders.BatchFixer and delete the 444-line copied implementation. Keep the shared facade to avoid changing dozens of individual code fixes. Specialized document-based and rule-specific providers remain unchanged.

Remove the test verifier's prohibition on the compiler batch fixer, add positive provider-contract and document/project/solution scope-boundary tests, and update the status generator to recognize the compiler provider. Document the host-dependent implementation in CONTRIBUTING.md.

Analyzer execution is unchanged: no new registrations, semantic calls, caches, or per-analysis allocations. Shipped Roslyn dependencies remain pinned to 1.2.1. The Release code-fix DLL shrank from 492,544 to 473,600 bytes (18,944 bytes, about 3.8%).

Review considerations: newer hosts may expose additional built-in Fix All scopes and compiler-owned titles. The memory results favor the replacement overall, but do not establish a universal memory improvement. The proposal is intentionally retained despite the semantic-workload caveats below, as requested.

Allocation and elapsed-time investigation

Paired Release BenchmarkDotNet 0.15.8 comparisons used baseline DLLs from a069a5dda5d1a78c4292b5944b638bd2c9d490ad, the same individual code fixes, prebuilt immutable solutions, and precomputed real analyzer diagnostics. Each operation includes both GetFixAsync and GetOperationsAsync through the merged ApplyChangesOperation.ChangedSolution, including final cleanup. Setup, diagnostic discovery, and exact output-text validation are outside the measured operation. Both implementations' output was checked before measurement.

Environment: Windows 11 25H2, SDK 10.0.401, .NET 10.0.12 x64, concurrent workstation GC, default tiering. Primary confirmation used Roslyn 5.10.0-1.26477.9, one launch, three warmups, ten measured iterations, and one operation per iteration.

Workload Custom allocations/op Built-in allocations/op Reduction Custom elapsed Built-in elapsed
SA1018: 1,000 diagnostics in one document 406.48 MiB 385.97 MiB 5.0% 613.73 ms 433.61 ms
SA1018: 1,000 diagnostics across 100 documents, one project 1,383.25 MiB 93.09 MiB 93.3% 2,861.64 ms 173.57 ms
SA1018: 1,000 diagnostics across 100 documents, ten projects 1,352.37 MiB 88.53 MiB 93.5% 2,815.07 ms 81.15 ms
SA1312: 100 unused-local-to-discard fixes in one document 9.03 MiB 8.91 MiB 1.3% 113.86 ms 12.63 ms
SA1313: 100 parameter renames across ten documents 67.70 MiB 57.49 MiB 15.1% 298.3 ms 149.4 ms

Elapsed values are means, not latency guarantees. Reported 99.9% confidence-interval errors for custom/built-in were respectively: Dense +/-41.39/39.93 ms; Wide +/-97.96/26.42 ms; Solution +/-150.63/6.59 ms; Discard +/-11.63/0.35 ms; Rename +/-90.83/21.81 ms. Some fast iterations were below BenchmarkDotNet's recommended 100 ms, its default policy removed some outliers, and rename timing was noisy.

Separate screening with Roslyn 5.0.0 showed similar allocation results: approximately 93% less across many documents/projects, 5% less in the dense document, and almost unchanged for discards.

Peak and retained memory tradeoffs

Fresh-process snapshots warmed only the selected provider, forced GC, sampled managed heap/working set/private bytes every 10 ms during one operation, and forced GC again for retained heap. These are medians of three processes using current Roslyn and default processor count. Pairs are custom -> built-in, in MiB.

Workload Sampled peak managed heap Peak working set during operation Peak private bytes during operation Retained heap after forced GC
Dense 130.6 -> 137.6 252.3 -> 261.5 185.0 -> 195.1 9.0 -> 12.1
Wide 99.4 -> 77.4 229.0 -> 201.1 159.0 -> 137.2 25.1 -> 25.7
Solution 94.1 -> 51.4 361.2 -> 307.5 291.7 -> 241.8 25.2 -> 25.4
Discard 16.9 -> 30.8 129.2 -> 146.6 62.1 -> 79.4 7.7 -> 21.6
Rename 29.5 -> 59.3 159.9 -> 201.8 83.1 -> 126.3 11.4 -> 20.2

Thus, lower total allocation did not always mean lower memory consumption. Semantic cases retained approximately 14 MiB more for discards and 9 MiB more for renames on this high-core-count host. Clearing fixture references, disposing the workspace, and forcing GC still left differences of similar magnitude; this does not identify retained-object roots or prove a leak.

A short 20-repeat experiment showed discard heap changing from 7.7 to 7.9 MiB custom and 21.3 to 22.3 MiB built-in; rename changed from 11.2 to 11.9 MiB custom and 20.6 to 18.7 MiB built-in. It did not show large unbounded growth, but cannot rule out longer-lived IDE retention.

A diagnostic configuration with DOTNET_PROCESSOR_COUNT=8 reduced the retained-heap differences to roughly 1.3 MiB for discards and 0.5 MiB for renames. Rename peak heap then improved from 27.4 to 18.1 MiB, and working sets were essentially equal. Default-host semantic runs used approximately 107-112 thread-pool threads custom versus 136-197 built-in. This supports a parallelism-sensitive tradeoff, not proof of a particular retained-object root. No parallelism restriction is added to product code.

Attribution, stress test, and limitations

Unelevated EventPipe allocation/thread-time traces of a warmed 30-second repeated Wide workload on Roslyn 5.0 showed prominent formatter dictionaries, syntax-traversal iterators, Task<Document> objects, and semaphore task nodes in the custom implementation. Allocation stacks include FormatterShared.FormatAsync, CodeCleanupHelpers.CleanupSyntaxAsync, and CodeAction.RunCleanupPassesInOrderAsync. The copied implementation requests public preview operations for each individual fix; the compiler implementation accesses changed solutions internally and handles context/project merging differently. These stacks are consistent with the measured multi-document allocation reduction, not an exact attribution of every saved byte. Both implementations still perform cleanup, and the compiler trace also prominently includes semantic compilation/import-adder work. Trace totals are not compared because the providers complete different operation counts per 30 seconds; sampled thread-time includes waiting, not just on-CPU execution.

A built-in-only stress run with ten projects, 1,000 documents, and 10,000 diagnostics validated every output: 2.33 seconds, about 946 MiB allocated, 284 MiB sampled peak heap, and 583 MiB peak working set during the operation. The original paired run at that size was stopped after several minutes; no matched custom result exists, so no ratio is claimed.

These are deterministic synthetic workloads, not an actual Visual Studio session or a customer solution. There was no IDE-host memory measurement, .NET Framework performance comparison, heap-root dump, hardware-counter collection, or kernel ETW profiling. Roslyn 1.3.2 correctness was exercised, but its allocations were not benchmarked. Modern-host results should not be generalized to every supported compiler.

The session retains the benchmark source, baseline DLLs, BenchmarkDotNet reports, raw traces, snapshot JSONL, and a full experiment/reproduction report outside source control. Temporary profiler/parser binaries were cleaned up. No benchmark dependencies or generated reports are shipped in this PR.

Validation

  • Full Release solution builds with zero warnings/errors.
  • Roslyn 1.3.2 full suite: 7,235 passed before the final three scope cases were added; all five new provider/scope cases passed separately afterward.
  • Newest compiler full suite: 9,761 passed.
  • Targeted document/project/solution scope and SA1018 tests passed on .NET Framework 4.7.2 as well as .NET 10.
  • Status generator executed successfully: SA1018/SA1312 remain BatchFixer; SA1028 remains CustomImplementation.
  • The pre-existing whitespace-only ruleset edit is excluded.

Opened as draft pending CI.

Replace the copied batch implementation with Roslyn BatchFixer while preserving specialized providers and status reporting. Add provider contract and scope boundary coverage.

For 1,000 syntax diagnostics across 100 documents, Roslyn 5.10 allocated about 93% less in paired Release benchmarks. Semantic workloads retained more memory on a 192-logical-processor host; an eight-processor diagnostic configuration reduced that overhead. Analyzer execution is unchanged.

Fixes #4211

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AArnott
AArnott marked this pull request as ready for review October 11, 2026 18:49
Copilot AI balanced review requested due to automatic review settings October 11, 2026 18:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new scope-boundary tests are not discovered against the newest compiler host.

1 open finding
What changed in this PR

Replaces the copied Fix All implementation with Roslyn’s host-provided batch fixer.

Changes:

  • Delegates the shared facade to WellKnownFixAllProviders.BatchFixer.
  • Removes the custom 444-line implementation.
  • Adds provider/scope tests, status-generator support, and contributor guidance.
File Description
CONTRIBUTING.md Documents host-dependent Fix All behavior and testing.
StyleCopCodeFixVerifier\2.cs` Permits the compiler batch provider in tests.
CustomFixAllProvidersTests.cs Tests provider identity and scope boundaries.
SolutionReader.cs Recognizes Roslyn’s batch provider.
CustomFixAllProviders.cs Delegates to the compiler provider.
CustomBatchFixAllProvider.cs Removes the copied implementation.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Derive a C# 15 test class so all five provider contract and scope cases are discovered against the current Roslyn host, not only Roslyn 1.3.2.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 11, 2026 18:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The facade still documents behavior specific to the deleted implementation.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Low severity Remove misleading facade contract about compiler change batching

StyleCop.Analyzers/​StyleCop.Analyzers.CodeFixes/​Helpers/​CustomFixAllProviders.cs:32

The retained remarks describe the deleted custom implementation, not the provider now returned here. In particular, the compiler implementation in current hosts obtains changed solutions internally (as the PR investigation notes), so it is not constrained to batching ApplyChangesOperation values from preview operations. Leaving this contract on the facade is misleading across supported hosts; remove it or explicitly make it host-dependent.

🧠 Review effort: Balanced

@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.36066% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.62%. Comparing base (a069a5d) to head (d8ee165).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4229      +/-   ##
==========================================
+ Coverage   97.55%   97.62%   +0.06%     
==========================================
  Files        1283     1283              
  Lines      136326   136089     -237     
  Branches     4404     4369      -35     
==========================================
- Hits       132994   132857     -137     
+ Misses       2173     2086      -87     
+ Partials     1159     1146      -13     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AArnott
AArnott merged commit 65a0d26 into master Oct 11, 2026
30 checks passed
@AArnott
AArnott deleted the aarnott-compiler-batch-fixer branch October 11, 2026 19:09
This was referenced Nov 11, 2026
This was referenced Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider using the compiler provided batch fixer

2 participants