Skip to content

Use hybrid C# reference map for post-processing#10976

Open
live1206 wants to merge 52 commits into
microsoft:mainfrom
live1206:mtg-hybrid-reference-map
Open

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

Conversation

@live1206

@live1206 live1206 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the C# generator's Roslyn-heavy generated-code reference-map construction with a provider/hybrid reference map while preserving generated-output correctness.

Why custom code still uses Roslyn

Generated code has provider metadata for signatures, body dependencies, serialization helpers, and known generated source patterns, so it can avoid building a full Roslyn reference map. Custom/shared code is arbitrary user C#: it can reference generated types through signatures, inheritance, generics, arrays, object creation, static members, extension methods, XML docs, or handwritten helper flows that provider metadata cannot see. This PR therefore keeps Roslyn semantic analysis for custom-code roots/references and uses the faster provider graph for generated-code reachability.

Latest benchmark data

Latest generator PR head: 48862512. Benchmark PR: #10885 (f4a1bbbec). Artifacts: /tmp/typespec-review-fix-bench-20260625-0637.

Scope Roslyn Provider/hybrid Improvement
Full generation median 918.3 ms / 68.02 MB 738.2 ms / 48.48 MB 19.6% faster / 28.7% less allocation
Reference-map profile median 307.7 ms / 23.64 MB 112.3 ms / 7.83 MB 63.5% faster / 66.9% less allocation

Azure SDK local project-reference benchmark

Measured Azure SDK for .NET management-plane regeneration using the same local project-reference setup in both runs: /workspaces/azure-sdk-for-net was wired to the sibling /workspaces/typespec checkout via .NET project references, and only the TypeSpec checkout changed between main and this PR branch.

SDK package TypeSpec main baseline This PR branch Improvement
Azure.ResourceManager.Network 00:37:01.9 00:17:23.9 53.0% faster / 2.13x speedup
Azure.ResourceManager.DataFactory 00:13:43.4 00:07:49.1 43.0% faster / 1.76x speedup

Validation

@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: 4886251

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

live1206 and others added 17 commits June 22, 2026 01:47
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>
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>
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>
@live1206 live1206 marked this pull request as ready for review June 25, 2026 08:58
@live1206 live1206 changed the title [Draft] Use hybrid C# reference map for post-processing Use hybrid C# reference map for post-processing Jun 25, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

public static void Analyze(IReadOnlyList<TypeProvider> providers, Project project)
{
var generatedProviders = GetGeneratedProviders(providers);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure why we have to exclude the custom code - we might produce incorrect result if custom code is not considered.
Also I think we should do it for CanonicalView of each provider.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

explained in PR description, and feel free to continue with this further improvement, I will not cover this part in current PR

Handle duplicate generated providers, avoid namespace-blind API baseline roots, and keep collection result constructors internal so implementation-only REST clients are not publicized.

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.

2 participants