Skip to content
Purview Dev logo

Performance

Stable SourceGenerator Framework Reviewed 2026-09-16 purview-dev/sourcegenerator-framework Star on GitHub 3 analyzers code-generation compile-time compiler csharp developer-experience developer-tools devex dotnet incremental-generator metaprogramming nuget roslyn source-generator source-generators testing

Benchmark results are produced by the benchmarks project (SourceGeneratorFramework.Benchmarks) using BenchmarkDotNet and folded here for reference.

All benchmarks measure the production code path: generator runs configure ValidateCodeWriterScopes = false and the writer is constructed with throwOnUnclosedScopes: false. Scope tracking is a testing/debug feature and is excluded here because capturing an opening StackTrace per scope dominates both time and allocation (for 1000 small classes it inflates the writer benchmark from ~1.6 ms/2.3 MB to ~19 ms/22 MB). Tests opt into it so an unclosed using or block fails fast; see Code-Writer.md.

  • BenchmarkDotNet v0.15.8
  • Windows 11 (10.0.28020.2991)
  • 13th Gen Intel Core i9-13900KF 3.00GHz, 1 CPU, 32 logical and 24 physical cores
  • .NET SDK 10.0.401
  • .NET 10.0.12 (10.0.12, 10.0.1226.42308), X64 RyuJIT x86-64-v3
  • Toolchain: InProcessEmitToolchain
MethodMeanErrorStdDevGen0Gen1Gen2Allocated
ManyClasses1.612 ms0.0139 ms0.0130 ms142.5781142.5781142.57812.34 MB
MethodMeanErrorStdDevGen0Gen1Allocated
RunAsync1.133 ms0.0182 ms0.0171 ms54.687511.71881.03 MB
MethodCountMeanErrorStdDevMedianRatioRatioSDAllocatedAlloc Ratio
EquatableArrayEquals104.1603 ns0.1068 ns0.1271 ns4.1864 ns1.0010.04-NA
EquatableArrayGetHashCode100.1677 ns0.0091 ns0.0085 ns0.1688 ns0.0400.00-NA
ImmutableArrayReferenceEquals100.0032 ns0.0069 ns0.0061 ns0.0000 ns0.0010.00-NA
ImmutableArraySequenceEqual103.7109 ns0.0374 ns0.0350 ns3.7080 ns0.8930.03-NA
EquatableArrayEquals10029.9631 ns0.2494 ns0.2333 ns29.9944 ns1.0000.01-NA
EquatableArrayGetHashCode1000.1705 ns0.0086 ns0.0081 ns0.1685 ns0.0060.00-NA
ImmutableArrayReferenceEquals1000.0029 ns0.0041 ns0.0038 ns0.0004 ns0.0000.00-NA
ImmutableArraySequenceEqual10029.3123 ns0.2250 ns0.2105 ns29.3094 ns0.9780.01-NA
EquatableArrayEquals1000189.2828 ns1.3004 ns1.2164 ns189.2343 ns1.0000.01-NA
EquatableArrayGetHashCode10000.1855 ns0.0109 ns0.0102 ns0.1817 ns0.0010.00-NA
ImmutableArrayReferenceEquals10000.0275 ns0.0178 ns0.0167 ns0.0251 ns0.0000.00-NA
ImmutableArraySequenceEqual1000191.8212 ns2.4799 ns2.3197 ns191.5713 ns1.0130.01-NA
MethodMeanErrorStdDevRatioGen0AllocatedAlloc Ratio
GetDeclaredSymbolFromNode115.5924 ns0.8672 ns0.7688 ns1.0000.001732 B1.00
PreResolvedTargetSymbol0.5658 ns0.0182 ns0.0170 ns0.005--0.00
MethodClassCountCompileToAssemblyMeanErrorStdDevGen0Gen1Allocated
RunAsync1False5.725 μs0.0552 μs0.0489 μs0.85450.213615.79 KB
RunAsync1True7,078.346 μs133.0041 μs124.4121 μs23.43757.8125458.51 KB
RunAsync10False7.579 μs0.0873 μs0.0729 μs1.01470.251818.73 KB
RunAsync10True7,746.954 μs150.9553 μs239.4311 μs23.43757.8125555.61 KB
RunAsync100False25.144 μs0.5020 μs0.5580 μs2.71610.427250.19 KB
RunAsync100True10,294.152 μs203.6992 μs382.5964 μs78.125015.62501552.67 KB
MethodMeanErrorStdDevAllocated
Int32Identity15.19 ns0.207 ns0.193 ns-
StringIdentity14.85 ns0.266 ns0.236 ns-
ListOfStringIdentity16.72 ns0.348 ns0.386 ns-
DictionaryIdentity16.61 ns0.289 ns0.271 ns-
NestedGenericIdentity16.43 ns0.323 ns0.303 ns-
MethodSpecCountMeanErrorStdDevGen0Gen1Allocated
RunAsync11.958 ms0.0297 ms0.0278 ms62.500011.71881.16 MB
RunAsync52.555 ms0.0368 ms0.0344 ms97.656323.43751.81 MB
RunAsync204.913 ms0.0965 ms0.1414 ms234.375039.06254.27 MB

Run the benchmarks project and copy the generated reports into the tables above:

Terminal window
dotnet run -c Release --project src/src/SourceGeneratorFramework.Benchmarks --framework net10.0

Filter to a single benchmark with --filter "*Name*". The Markdown reports are written to BenchmarkDotNet.Artifacts/results/.