You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use the compiler-provided batch Fix All provider - #4229
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.
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.
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>
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>
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.
❌ 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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.BatchFixertoWellKnownFixAllProviders.BatchFixerand 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 bothGetFixAsyncandGetOperationsAsyncthrough the mergedApplyChangesOperation.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.
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.
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=8reduced 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 includeFormatterShared.FormatAsync,CodeCleanupHelpers.CleanupSyntaxAsync, andCodeAction.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
BatchFixer; SA1028 remainsCustomImplementation.Opened as draft pending CI.