Skip to content

[http-client-csharp] Skip unnecessary simplifier passes#10846

Draft
live1206 wants to merge 14 commits into
microsoft:mainfrom
live1206:mtg-skip-unneeded-simplifier
Draft

[http-client-csharp] Skip unnecessary simplifier passes#10846
live1206 wants to merge 14 commits into
microsoft:mainfrom
live1206:mtg-skip-unneeded-simplifier

Conversation

@live1206
Copy link
Copy Markdown
Contributor

@live1206 live1206 commented Jun 1, 2026

Summary

Avoid running Roslyn Simplifier.ReduceAsync for generated documents that do not contain Simplifier.Annotation.

Previously, every generated document root was annotated with Simplifier.Annotation, which forced a full-document simplifier pass across all generated files. This removes the blanket root annotation and keeps the simplifier pass only for documents that still have targeted simplifier annotations after member removal and library rewriters.

Motivation

While profiling Azure.ResourceManager.Network generation through the Azure management generator, Roslyn post-processing dominated the direct .NET generator run time. The hotspot was Simplifier.ReduceAsync in the shared MTG GeneratedCodeWorkspace.ProcessDocument path.

Latest Network measurements as of 2026-06-02:

Manual end-to-end Network regeneration

Manual regen path Elapsed
TypeSpec/MTG on the Network migration branch 00:11:20.27
AutoRest.CSharp 00:08:19.39
Difference ~3m00.88

The current TypeSpec/MTG Network regen is still about 3 minutes slower than AutoRest.CSharp, so this PR improves the main measured MTG hotspot but does not eliminate the full regen gap.

Direct .NET generator phase isolation

Run Direct generator wall-clock Roslyn post-processing Simplifier behavior
Baseline profiling setup ~12m12s ~12m08s Simplified all generated documents
Current narrow-simplifier branch, fresh saved inputs ~8m13s ~7m53.9s Skips simplifier for documents with no remaining Simplifier.Annotation

The fresh current-branch direct-generator rerun produced 3,542 generated files, including 1,192 .Serialization.cs files. Roslyn post-processing was still ~96% of the isolated direct-generator time, confirming this remains the dominant hotspot even after the skip. The latest rerun improved the direct generator from the previous ~8m26s measurement to ~8m13s.

Notes

  • The criteria is annotation-based, not file-name or file-type based.
  • Documents with meaningful Simplifier.Annotation still go through Simplifier.ReduceAsync.
  • The local Roslyn 4.1.0 comparison was slower than 4.8.0, so this change focuses on reducing unnecessary simplifier work rather than changing Roslyn versions.

Validation

cd packages/http-client-csharp
pwsh ./eng/scripts/Generate.ps1
npm run test:generator

Targeted Spector coverage checks for the previously failing cases also passed locally:

pwsh ./eng/scripts/Get-Spector-Coverage.ps1 -filter http/payload/pageable
pwsh ./eng/scripts/Get-Spector-Coverage.ps1 -filter http/type/model/inheritance/recursive

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Jun 1, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 1, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10846

commit: 732a8fe

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

No changes needing a change description found.

live1206 and others added 13 commits June 1, 2026 07:30
Run simplification for documents containing global aliases so shared-source type names and generated sample code are reduced correctly while still skipping documents that do not need simplification.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Generate valid assignment statements without relying on Roslyn simplification, and keep shared-source test expectations aligned with the skip behavior so broad global-alias simplification is not reintroduced.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Refresh generated test projects and unit test expectations after skipping Roslyn simplification for documents without simplifier annotations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Avoid emitting a trailing space after array type syntax when the initializer is multiline. Regenerated outputs now match without manual generated-file whitespace edits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use plain default for known cancellation token optional parameters so generated code remains valid when documents are not passed through Roslyn simplification.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Refresh remaining generator unit test baselines after removing trailing spaces from multiline array initializers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant