Skip to content

[Draft] Use hybrid C# reference map for post-processing#10976

Draft
live1206 wants to merge 10 commits into
microsoft:mainfrom
live1206:mtg-hybrid-reference-map
Draft

[Draft] Use hybrid C# reference map for post-processing#10976
live1206 wants to merge 10 commits into
microsoft:mainfrom
live1206:mtg-hybrid-reference-map

Conversation

@live1206

@live1206 live1206 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a hybrid reference-map replacement for C# generated-code post-processing.

The hybrid path replaces Roslyn reference-map construction with:

  • provider metadata for generated-code references
  • a small Roslyn scan only for custom/shared code roots

No benchmark measurement/profiling code is included in the production generator path in this PR.

Why

The prior experimental PR measured full generation and identified Roslyn reference-map construction inside GeneratedCodeWorkspace.PostProcessAsync() as the largest hotspot.

That experiment also showed the hybrid map can match Roslyn decisions for Sample-TypeSpec and improve local full-generation performance.

Latest measured data from the experimental PR:

Mode Mean Error StdDev Allocated
Baseline Roslyn reference-map path 1.042 s 0.363 s 0.418 s 63.98 MB
Hybrid provider/custom map replacement 641.3 ms 98.37 ms 113.3 ms 44.41 MB

Approximate improvement:

Time:       ~38.5% faster
Allocation: ~30.6% less

Correctness Check

For Sample-TypeSpec, the hybrid candidates matched Roslyn exactly in shadow comparison:

Internalize:
Roslyn candidates: 32
Provider candidates: 32
Missing: 0
Extra: 0

Remove:
Roslyn candidates: 37
Provider candidates: 37
Missing: 0
Extra: 0

Validation

  • dotnet build packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Microsoft.TypeSpec.Generator.csproj -c Release passed.
  • dotnet test packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Microsoft.TypeSpec.Generator.Tests.csproj --filter "FullyQualifiedName~GeneratedCodeWorkspaceTests" passed: 8/8.

Next Step

Run SDK service regeneration and compare generated output.

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 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 2917111

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

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