Skip to content

DEMO: Benchmark DTO, direct converter, and manual UOPD JSON - #155

Open
Brennan1994 wants to merge 2 commits into
InvestigateExistingJsonfrom
DirectUncertainPairedDataJson
Open

Brennan1994 wants to merge 2 commits into
InvestigateExistingJsonfrom
DirectUncertainPairedDataJson

Conversation

@Brennan1994

@Brennan1994 Brennan1994 commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

DEMO comparison of three JSON strategies for UncertainOrderedPairedData, based on InvestigateExistingJson (#152). All retain the IList API, existing distribution converter, list ownership, and collection validation. The DTO converter remains the default.

  1. DTO: the collection converter serializes/deserializes a private UncertainOrderedPairedDataDto. Ordinates use attributes and the existing distribution converter.
  2. Direct converter: a converter reads/writes collection properties directly, while ordinate-list serialization still passes through JsonSerializer. Register this alternative in JsonSerializerOptions.
  3. Fully manual: UOPD.ToJson()/FromJson() handle the collection, and UncertainOrdinate writes/reads directly through the shared writer/reader. Only distribution handling goes through the existing converter. The manual path uses no DTO or serializer attribute processing.

Direct and manual implementations explicitly handle required properties, unknown properties, non-finite numbers, and invalid inputs. The manual path uses case-sensitive default property names and numeric enums; it does not support custom serializer options. It rejects null Y distributions, computes ordinate validity when reading, and validates the completed collection once.

Benchmark results

BenchmarkDotNet 0.15.8, Release, .NET 10.0.9 x64 on Windows 11; one launch, five warmups, fifteen measurement iterations per case. Fixture: X=i, Y=Normal(10*i,1), strict ascending ordering, and default NaN tail probability. Setup verifies identical JSON and reconstructed data. Operations use JSON strings; deserialization includes validation. CPU model was not detected and BenchmarkDotNet could not change the power plan.

Each cell is mean elapsed microseconds / managed bytes allocated per call. Allocations are not peak live memory. All results come from the same 18-case run.

Operation Ordinates DTO Direct converter Fully manual
Deserialize 10 9.797 / 5,184 10.119 / 5,512 7.190 / 4,184
Deserialize 100 86.821 / 44,472 89.167 / 44,800 64.822 / 38,256
Deserialize 1,000 872.133 / 425,952 870.026 / 426,280 654.382 / 369,336
Serialize 10 3.749 / 2,384 4.151 / 2,336 3.827 / 8,544
Serialize 100 34.646 / 17,864 34.188 / 17,816 33.613 / 34,832
Serialize 1,000 392.166 / 176,295 393.864 / 176,247 377.407 / 272,023

Manual deserialization uses 25-27% less time and allocates 13-19% fewer bytes than the DTO. At 1,000 ordinates, that saves about 218 microseconds and 56,616 allocated bytes per call. Across strategies, deserialization time and allocations scale approximately linearly.

Manual serialization provides small timing gains at larger sizes but allocates substantially more: at 1,000 ordinates, about 4% less time and 54% more allocated memory. Its Utf8JsonWriter-over-MemoryStream implementation uses writer and stream buffers in addition to the returned string. The serializer paths benefit from reusable writers and pooled buffers. Consequently, this comparison includes buffer-management differences as well as property-handling differences; it does not establish an inherent allocation penalty for manual JSON writing.

The direct converter does not consistently improve timing over the DTO. It saves 48 bytes per write but adds 328 bytes per read, where it allocates outer property-name strings. At 1,000 ordinates, DTO/direct timing confidence intervals overlap for both operations. Manual/DTO write intervals also overlap at 10 ordinates.

The full table, interpretation, methodology, and repeat command are saved at the top of UncertainPairedDataConverterBenchmarks.cs.

Validation

  • dotnet build -c Release: passed with zero warnings and errors.
  • dotnet test -c Release --no-build --filter "TestCategory!=LiveServiceIntegration": 4,153 passed on net10.0 and 4,136 passed on net481; zero failures or skipped tests.
  • All 18 BenchmarkDotNet cases completed successfully.
  • Regression coverage includes equivalent JSON and reconstructed data, list reuse, null/missing input, malformed roots, unknown/reordered fields, non-finite numbers, mixed distributions, recomputed validity, and tail validation. Converter tests also cover caller serializer options.
  • Python tests skipped at the user's request. Coverage-registry exclusions document the experimental converter and manual JSON methods.

@Brennan1994 Brennan1994 changed the title DEMO: Benchmark DTO and direct UOPD JSON converters DEMO: Benchmark DTO, direct converter, and manual UOPD JSON Dec 4, 2026

This branch has not been deployed

No deployments
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.

1 participant