[Draft] Experiment with manual C# name reduction#10885
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 59eb312.
commit: |
|
No changes needing a change description found. |
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>
Network post-processing performance experiment resultsDocumenting the current experiment state before switching back to the Network MPG migration work. Network generator-only timingAll runs used the saved Network generator inputs from
Artifacts: Bounded parallelism follow-upI also tried an env-var-gated bounded document-processing experiment (
Artifacts: ConclusionThis PR is useful as an experiment, but the manual reducer approach is not currently a Network performance improvement. The bounded-parallelism experiment was removed from the working tree after it failed to beat Recommended next direction is deeper phase/document-size instrumentation around Roslyn workspace post-processing, then target reducing the number or size of documents that go through semantic simplification rather than replacing Roslyn simplification wholesale. |
|
Latest shadow-map replacement results from local BenchmarkDotNet runs. Correctness Shadow ComparisonReplacement mode still compares the provider/custom-code hybrid candidates against the Roslyn candidates before using them. This is for Full-Generation BenchmarkBenchmark command shape: DOTNET_ROOT="$HOME/.dotnet" PATH="$HOME/.dotnet:$PATH" \
dotnet run --project packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj \
-c Release --framework net10.0 --filter "*FullGenerationBenchmark*"Replacement mode additionally used: TYPESPEC_PROVIDER_REFERENCE_MAP_SHADOW=true
TYPESPEC_PROVIDER_REFERENCE_MAP_USE_SHADOW=true
TYPESPEC_PROVIDER_REFERENCE_MAP_SHADOW_DIR="/tmp/typespec-provider-reference-map-shadow"
Approximate improvement: InterpretationThe hybrid provider/custom-code map is now exact for Next step: create a clean PR from latest |
Summary
This PR adds full-generation benchmark/profiling coverage for generated C# and uses it to identify the largest hotspots in the end-to-end generator path.
The latest full-generation data shows that reference-map construction inside
GeneratedCodeWorkspace.PostProcessAsync()is the larger hotspot. RoslynSimplifier.ReduceAsyncis not part ofPostProcessAsync(); it runs later insideGetGeneratedFilesAsync()while final generated documents are processed before writing to disk.The earlier manual name-reduction experiment was removed. It did not improve performance and became slower than the original Roslyn simplifier path on scaled generated-code corpora.
What Changed
Sample-TypeSpec.PostProcessAsync(),GetGeneratedFilesAsync(), and file writes.Simplifier.ReduceAsyncas the existing final document simplification path.How To Run
Full generation:
Enable per-step profile files:
POSTPROCESSING_BENCHMARK_PROFILE_STEPS=true POSTPROCESSING_BENCHMARK_PROFILE_DIR="/tmp/typespec-post-processing-profiles"Latest Full-Generation Benchmark Findings
Dry-run smoke result for
FullGenerationBenchmark.GenerateSampleTypeSpecProject:GenerateSampleTypeSpecProjectFull-generation phase profile:
Generation.PostProcessAsyncGeneration.WriteGeneratedFilesToDiskGetGeneratedFilesAsync()final document processing plus file writesGeneration.WriteTypeProvidersGeneration.CreateSourceInputModelGeneration.BuildTypeProvidersGeneration.ResolveExternalTypeReferencesPostProcessAsync()HotspotDeeper profiling shows that reference-map construction dominates
GeneratedCodeWorkspace.PostProcessAsync():PostProcess.InternalizeAsyncPostProcess.RemoveAsyncPostProcessor.Internalize.BuildPublicReferenceMapAsyncPostProcessor.Remove.BuildAllReferenceMapAsyncReference-map construction inside
PostProcessAsync()accounts for roughly:GetGeneratedFilesAsync()SubphaseSimplifier.ReduceAsyncruns inGetGeneratedFilesAsync(), not inPostProcessAsync().In the same full-generation run:
Roslyn.Simplifier.ReduceAsyncCompared with the larger full-generation hotspot:
Conclusion
The largest full-generation hotspot is
PostProcessorreference-map construction insideGeneratedCodeWorkspace.PostProcessAsync().Simplifier.ReduceAsyncis a separate hotspot insideGetGeneratedFilesAsync()final document processing, but it is not part ofPostProcessAsync()and is not the largest full-generation issue.This PR should be used as a benchmarking/profiling basis for future optimization work. The next likely optimization target is reference-map construction in
PostProcessor.Validation
dotnet build packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/perf/Microsoft.TypeSpec.Generator.Tests.Perf.csproj -c Releasepassed.dotnet test packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Microsoft.TypeSpec.Generator.Tests.csproj --filter "FullyQualifiedName~GeneratedCodeWorkspaceTests"passed: 8/8.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com