Json codec improvements - #4
Merged
Merged
Conversation
Generated records now carry an intrinsic `static member Schema: T -> Schema<T>` augmentation delegating to the sibling `let schema`, so a bare `fieldAs "x" _.Field` on a contract-typed field resolves through the same SRTP constraint a `string` field uses (including the list/option/map witnesses). The augmentation is intrinsic to the generated file, so it satisfies the constraint cross-assembly with no `open`. Gated on `contract.OwnsType`: `[<DeriveSchema>]` types on hand-written records are not declared by schemagen, so they keep `withSchema TheType.schema`. Regenerated the .contract corpus goldens; added a GeneratedContractTests case covering direct, list, and option nesting. Claude-Session: https://claude.ai/code/session_01BhazQLVh4zWAfZsjTxczVS
- Ship "sideEffects": false for every Fable-compiled package, so a browser bundler drops Reified.Constraint/Refinements entirely from a schema that never uses a refined field or constraint. - Guard it: the Fable build target fails if the generated JS grows a top-level side effect. - Codec: sprintf/failwithf -> string concat, F# Map -> assoc lists in union decoding. Drops the printf parser and Map.js from every codec that doesn't need them. No .NET behaviour change.
- New "Browser bundle size" section: the sideEffects contract and a cost table per feature (schema only, +codec, +constraints, +refined types). - Record the reasoning in dev-docs/decisions. - Re-run the codec benchmarks. Allocations are unchanged from the prior run, confirming the codec change is perf-neutral.
- Json.serializeIndented for pretty output; Json.reindent to pretty-print any JSON string. - Json.serializeWith/serializeBytesWith/serializeToStreamWith take a JsonWriteOptions configure function (indent, trailing newline, ASCII-only, HTML-safe escaping) - same shape as Schema.parseWith. - Implemented as one pass over the compact bytes, so serialize/serializeBytes/serializeToStream are untouched.
- Add alias and aliases field-block operations with exact, case-sensitive names.\n- Parse and decode canonical names or aliases while encoding only the canonical name.\n- Reject ambiguous input and schema-wide name collisions; expose aliases through inspection.\n- Document compatibility guidance and cover parsing, codecs, API shape, and collisions.
- Preserve duplicate object properties with a linear dictionary index during Schema.parse.\n- Keep canonical JSON matching on the direct UTF-8 fast path and scan aliases only after a miss.\n- Add SchemaAlias derivation metadata and generated alias operations.\n- Add standalone Field.withAlias composition and Fable runtime coverage.
Compare canonical parsing, alias parsing, duplicate-name rejection, and compiled alias decoding on the shared customer fixture. Keep this benchmark commit at the branch tip so measured documentation can be amended from the final implementation.
Decode Reified's canonical field order through the typed constructor chain without field dispatch or per-field slots. On any layout mismatch, restart through the existing unordered and alias-aware decoder without exposing a mode choice. Keep malformed field values final and preserve their paths.
Measure the canonical decoder against System.Text.Json, the general reverse-order fallback, and an optimistic known-layout scan ceiling. Refresh the recorded codec, boundary, wide-record, and collection results from the final implementation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Shows a 24-field decode around 19% faster than System.Text.Json.