Skip to content

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

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

[http-client-csharp] Skip unnecessary simplifier passes#10846
live1206 wants to merge 7 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 run time. The hotspot was Simplifier.ReduceAsync in the shared MTG GeneratedCodeWorkspace.ProcessDocument path.

Local profiling results for direct Network generator runs:

Run Direct generator wall-clock Roslyn post-processing Simplifier behavior
Baseline ~12m12s ~12m08s Simplified all generated documents
Narrow simplifier experiment ~8m03s ~7m59s Skipped simplifier for 3,273 / 4,171 documents

This is about a 4m09s improvement for the direct Network generator run.

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

dotnet build packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Microsoft.TypeSpec.Generator.csproj --configuration Release --framework net10.0 --no-incremental

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: 603b4bb

@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 6 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>
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