Skip to content

perf(validation): decode serialized snapshots without reencoding #252

Closed

Description

@jinxiao

Affected modules

validation

Problem and use case

The default validation compiler marshals an input into a private JSON snapshot, then calls jsonValue(snapshot), which marshals those already serialized bytes again before exact-number decoding. A similar duplicate conversion exists for external schema registration. Large payloads pay for avoidable encoding and temporary buffers.

Proposed behavior

Decode already serialized, validated JSON bytes directly with the existing JSON v2 exact-number options. Reuse a small internal decoding helper at the known serialized call sites while retaining the original snapshot for diagnostic ordering. Ordinary Go/custom inputs still go through JSON v2 marshaling.

Alternatives considered

Skipping normalization or using float64 would change exact numeric validation and ownership. Global raw-JSON shortcuts could change errors for invalid/empty raw values. Keep the shortcut scoped to bytes already produced by the existing marshaler.

Acceptance criteria

  • Preserve exact numeric tokens, diagnostic ordering, invalid input errors, once-only custom callbacks, schema registration and input isolation.
  • Existing validation/reference suites plus focused regressions and a representative large-payload benchmark pass.
  • Packaged validation/consumers pass with CGO disabled; update CHECKLIST and measured evidence after verification.
  • No new JSON implementation/dependency, schema dialect feature, public API or release.

Compatibility and dependencies

JSON v2 defaults and the existing exact-number interoperability remain unchanged. Draft 4/6 feature work stays out of scope.

Before submitting

  • I searched existing issues and the roadmap for this proposal.
  • I removed credentials and private data from examples.

Activity

  1. added
    enhancementNew feature or request
    module:validationIssues affecting the validation module
    priority:P2Normal: planned work without an urgent blocker
    on Oct 15, 2026
  2. jinxiao commented on Oct 15, 2026

    @jinxiao
    ContributorAuthor

    Scope accepted for implementation. Starting direct decoding only at already serialized snapshot boundaries, retaining exact-number and diagnostics behavior; coordinated with #250 and #251.

  3. jinxiao commented on Oct 15, 2026

    @jinxiao
    ContributorAuthor

    Implemented in #253. Exact numeric tokens, once-only marshaler failures, diagnostic snapshot ownership and the existing validation suite pass. Local large-string Validation decreases from 4.76 to 2.96 ms; complete packaged/consumer evidence is recorded. This issue remains open until the PR merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmodule:validationIssues affecting the validation modulepriority:P2Normal: planned work without an urgent blocker

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions