Skip to content

Add a direct JSON source generator using PolyType.Roslyn - #553

Merged
eiriktsarpalis merged 3 commits into
mainfrom
eiriktsarpalis-fast-json-generator
Oct 27, 2026
Merged

eiriktsarpalis merged 3 commits into
mainfrom
eiriktsarpalis-fast-json-generator

Conversation

@eiriktsarpalis

Copy link
Copy Markdown
Owner

Adds PolyType.FastPathJson, a toy proof of concept showing that the PolyType.Roslyn models can drive direct JSON code generation rather than runtime type shapes.

[GenerateJson] and [GenerateJsonFor<T>] generate IJsonSerializable<T> implementations with static Utf8JsonWriter/Utf8JsonReader operations. Neither prototype project depends on PolyType.dll or the built-in generator. Shared type-naming helpers move to PolyType.Roslyn, and writer pooling is source-linked from the example serializer.

Coverage compares representative PolyType.TestCases values with the example JSON serializer and checks generator diagnostics, incrementality, composition and caller-owned readers/writers. The existing JSON benchmarks gain the prototype as a comparator, with refreshed charts. The prototype README also records the matched Native AOT image-size comparison; the one-off comparison apps are not included.

The prototype is not intended for production use or packaging.

make test passed, as did the benchmark project's --validate-json output and round-trip checks for all nine fixtures.

Add the FastPathJson proof of concept, shared-case parity and snapshot coverage, and JSON benchmark comparisons. Share generator naming and writer-pooling helpers and record the Native AOT size comparison.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8dfb9bb0-f3f6-42c4-8ca5-68429ff44ac7
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.85000% with 103 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.46%. Comparing base (984ba23) to head (9e20030).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...lyType.FastPathJson/Converters/ScalarConverters.cs 82.59% 41 Missing and 14 partials ⚠️
...Type.FastPathJson.SourceGenerator/Parser/Parser.cs 93.93% 5 Missing and 16 partials ⚠️
.../PolyType.FastPathJson/Converters/EnumConverter.cs 93.95% 4 Missing and 5 partials ⚠️
...pe.FastPathJson/Converters/CollectionConverters.cs 93.44% 4 Missing ⚠️
...c/PolyType.Roslyn/Helpers/TypeIdentifierHelpers.cs 92.50% 3 Missing ⚠️
...SourceGenerator/SourceFormatter/SourceFormatter.cs 97.95% 0 Missing and 3 partials ⚠️
.../PolyType.FastPathJson/Converters/ScalarHelpers.cs 94.54% 2 Missing and 1 partial ⚠️
...hJson.SourceGenerator/Parser/DataModelExtractor.cs 98.18% 0 Missing and 2 partials ⚠️
...json/PolyType.FastPathJson/GenerationAttributes.cs 0.00% 2 Missing ⚠️
...rc/PolyType.Examples/Utilities/ByteBufferWriter.cs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #553      +/-   ##
==========================================
+ Coverage   94.20%   94.46%   +0.25%     
==========================================
  Files         259      299      +40     
  Lines       17641    19556    +1915     
  Branches     3418     3813     +395     
==========================================
+ Hits        16619    18473    +1854     
- Misses        770      795      +25     
- Partials      252      288      +36     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

eiriktsarpalis and others added 2 commits October 27, 2026 20:57
Exercise invalid and segmented scalar inputs, collection witness contracts, enum validation, generator diagnostics, and collection factory signatures through the public entry points. Preserve the existing coverage targets and test cases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8dfb9bb0-f3f6-42c4-8ca5-68429ff44ac7
Rerun all 99 JSON benchmarks with six warmups and twelve measurement iterations. Refresh the charts, exported measurements, machine details, and performance comparisons.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@eiriktsarpalis
eiriktsarpalis merged commit 429bae8 into main Oct 27, 2026
8 of 9 checks passed
@eiriktsarpalis
eiriktsarpalis deleted the eiriktsarpalis-fast-json-generator branch October 27, 2026 19:40
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