[Draft] Add generated C# full-generation benchmarks#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 |
…tion-experiment # Conflicts: # packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs # packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/PostProcessing/GeneratedCodeWorkspace.cs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
You can try these changes here
|
Summary
This PR is now a benchmark/profiling PR for generated C# full generation and post-processing performance.
It adds full-generation benchmark/profiling coverage and records the current performance evidence that motivated the production hybrid reference-map work in #10976. The earlier manual C# name-reduction experiment was removed because it did not improve performance 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 benchmark:
Enable per-step profile files:
POSTPROCESSING_BENCHMARK_PROFILE_STEPS=true POSTPROCESSING_BENCHMARK_PROFILE_DIR="/tmp/typespec-post-processing-profiles"Latest Benchmark Data
Latest combined BenchmarkDotNet run after final provider dependency/parity fixes:
1,298.5 ms63.51 MB899.8 ms49.38 MBApproximate improvement by mean:
Benchmark notes:
UseProviderReferenceMapparameter.WarmupCount=1,MinIterationCount=15,MaxIterationCount=20,IterationTime=250 ms..NET 10.0.9, Ubuntu 26.04, AMD EPYC 7763./tmp/typespec-bench-explicit-deps/results/Microsoft.TypeSpec.Generator.Perf.FullGenerationBenchmark-report-github.md.Focused Reference-Map Data
Focused profiling separates the two Roslyn reference-map phases and compares them with the provider replacement:
172.6 ms11.43 MB233.3 ms11.21 MB405.8 ms22.64 MB225.9 ms12.81 MB~0.55 ms~38 KBApproximate focused improvement for the reference-map replacement:
Provider analysis computes internalize/remove candidates together in one pre-pass, so it does not naturally split the same way as the old Roslyn
InternalizeAsyncandRemoveAsyncphases.Full-Generation Hotspot Data
Dry-run smoke result for
FullGenerationBenchmark.GenerateSampleTypeSpecProject:GenerateSampleTypeSpecProject1.603 s64.28 MBFull-generation phase profile:
Generation.PostProcessAsync949.775 ms60.4%29,755,928 BGeneration.WriteGeneratedFilesToDisk369.231 ms23.5%18,160,224 BGetGeneratedFilesAsync()final document processing plus file writesGeneration.WriteTypeProviders116.061 ms7.4%5,799,832 BGeneration.CreateSourceInputModel50.538 ms3.2%1,533,832 BGeneration.BuildTypeProviders40.014 ms2.5%4,618,616 BGeneration.ResolveExternalTypeReferences30.133 ms1.9%6,538,112 BPostProcessAsync()BreakdownReference-map construction dominates
GeneratedCodeWorkspace.PostProcessAsync():PostProcess.InternalizeAsync517.453 ms16,235,712 BPostProcess.RemoveAsync432.280 ms13,520,216 BPostProcessor.Internalize.BuildPublicReferenceMapAsync353.832 ms11,319,552 BPostProcessor.Remove.BuildAllReferenceMapAsync390.248 ms11,306,400 BReference-map construction inside
PostProcessAsync()accounts for roughly:GetGeneratedFilesAsync()SubphaseSimplifier.ReduceAsyncruns inGetGeneratedFilesAsync(), not inPostProcessAsync().In the same full-generation run:
Roslyn.Simplifier.ReduceAsync349.972 ms6.862 ms17,455,096 BCompared with the larger full-generation hotspot:
Latest Validation Data
Local validation performed while stabilizing the benchmark and production follow-up included:
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.RegenPreview.ps1 -Azure -Unbrandedcompleted successfully for42/42libraries.00:14:28; previous clean run:00:11:41.Representative regenerated package builds exposed additional Azure custom-stub accessibility issues in the production follow-up branch. Those are correctness follow-ups for #10976, not benchmark instrumentation issues in this PR.
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 the benchmark/profiling basis for generated C# post-processing optimization work. The production implementation lives separately in #10976.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com