Skip to content

Benchmark source-generated deserialization - #175

Merged
xoofx merged 1 commit into
xoofx:mainfrom
Mpdreamz:bench/source-generated-deserialize
Nov 4, 2026
Merged

xoofx merged 1 commit into
xoofx:mainfrom
Mpdreamz:bench/source-generated-deserialize

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

SourceGeneratedBenchmarks now also covers deserialization through a generated context, including a << merge key, so a change to the generated readers can show up in the benchmarks.

Why

The class only had serialization benchmarks, and the POCO deserialize benchmarks call YamlSerializer.Deserialize<T>(yaml) rather than a generated reader. A change to the source generator's readers, such as #172 and #174, could not be measured with the existing benchmarks at all.

What

  • SharpYaml_SourceGenerated_Deserialize and YamlDotNet_StaticGenerator_Deserialize read the same large document that the serialize benchmark writes, as a baseline-and-comparison pair in the Deserialize_SourceGenerated category.
  • SharpYaml_SourceGenerated_Deserialize_MergeKeys reads a small DatabaseConfiguration where most members come from a << mapping, in its own category so its ratio is not mixed with the large document.

Results

BenchmarkDotNet default job, 3 runs per figure on one machine (Apple silicon, .NET 10):

Benchmark Mean Allocated
SharpYaml_SourceGenerated_Deserialize 1.21–1.27 ms 1,917,840 B
YamlDotNet_StaticGenerator_Deserialize 2.05–2.14 ms about 4.1 MB
SharpYaml_SourceGenerated_Deserialize_MergeKeys 2.0–2.1 µs 6,896 B

I used these to check #172 and #174. Over three alternating runs of main against those changes, time stays within run-to-run noise. A first version of #172 allocated 48 bytes per object read, which this benchmark caught and #172 now fixes.

Run

cd src
dotnet run -c Release --project SharpYaml.Benchmarks -- --filter "*SourceGenerated*Deserialize*"

🤖 Generated with Claude Code

SourceGeneratedBenchmarks only covered serialization, so a change to the generated readers could not show up in the benchmarks. Adds a generated-context deserialization of the large document, compared with the YamlDotNet static generator, and a deserialization that goes through a `<<` merge key.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xoofx
xoofx merged commit ac6f714 into xoofx:main Nov 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants