perf(http-client-csharp): avoid Roslyn simplifier for type names#10916
Draft
ArcturusZhang wants to merge 10 commits into
Draft
perf(http-client-csharp): avoid Roslyn simplifier for type names#10916ArcturusZhang wants to merge 10 commits into
ArcturusZhang wants to merge 10 commits into
Conversation
Emit C# type names through a per-file analyzer that collects referenced types, uses a namespace prefix trie to choose safe imports/qualifications, and omits global:: in the optimized path. Skip Roslyn Simplifier.ReduceAsync when no custom rewriters require it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
No changes needing a change description found. |
Resolve ambiguous type names with full namespace qualification instead of invalid namespace suffixes, and emit compound assignment statements without parentheses so generated code remains compilable without Roslyn simplification. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep expression statement writing unchanged for now and leave non-type Roslyn simplifications out of the type-name resolver change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move per-file type reference collection into CodeWriter and add a BenchmarkDotNet benchmark comparing the legacy Roslyn simplifier path with the optimized resolver path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make CodeWriter collect file-local type references and construct CSharpTypeNameResolver per generated file instead of storing a global resolver built from all TypeProviders. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ifier Use expression-context precedence when direct type-name resolution skips Roslyn simplification, keeping legacy formatting unchanged outside that path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Write binary expressions without outer defensive parentheses and parenthesize nested expression nodes at expression-use sites instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace type checks in nested expression writing with a virtual ShouldParenthesize property on expression nodes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Write assignment values directly because C# assignment precedence preserves RHS grouping without requiring additional parentheses. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the in-process benchmark override now that the expected .NET SDK is available for the perf project. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR moves C# type-name simplification into the generator's write path so the common no-rewriter path can skip Roslyn
Simplifier.ReduceAsync.Changes
CSharpTypereferences per generated.csfile inCodeWriter.global::in the optimized path.GeneratedCodeWorkspaceNameResolverBenchmarkcovering writer + generated workspace post-processing.Performance
Benchmark:
GeneratedCodeWorkspaceNameResolverBenchmarkwith 100 models and 10 properties per model.This benchmark shows the optimized path is about 3x faster and allocates about 13% of the legacy path for the synthetic generated-workspace scenario.
Validation
dotnet build packages/http-client-csharp/generatordotnet test packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Microsoft.TypeSpec.Generator.Tests.csproj --filter FullyQualifiedName!~GeneratorHandlerTestsdotnet test packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csprojdotnet run -c Release --framework net10.0 --filter *GeneratedCodeWorkspaceNameResolverBenchmark*frompackages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf