Skip to content

JSON: emit flat Latin-1 strings without transcode storage #778

Description

@chrisbbreuer

Parents: #473, #480
Related: #675, #777

Problem

With production flat Latin-1 StringCell storage enabled, JSON.stringify currently calls Value.asWtf8 for every string value. Eligible strings are first transcoded into temporary arena storage and then copied again into the authoritative JSON output buffer. The property-key writer already writes canonical storage directly, and structured clone already has a representation-aware final-buffer writer.

Scope

  • Add a representation-aware JSON string writer for String Values.
  • Borrow ASCII and canonical WTF-8 storage directly.
  • Encode physical flat Latin-1 directly into the authoritative output buffer while applying QuoteJSONString escapes.
  • Preserve lone-surrogate escaping, control/quote/backslash escapes, astral and BMP content, replacer/toJSON ordering, omission rollback, output limits, and OOM atomicity.
  • Prove a capacity-prepared flat-string write succeeds with an allocator that fails its first allocation.

No-workaround rules

  • No permanent canonical shadow copy, eager global canonicalization, lossy replacement, invalid-byte acceptance, alternate JSON semantics, hidden second pass, or benchmark/input special case.
  • No stack, queue, job, Promise, Worker, or Map/Set iterator implementation changes.

Acceptance

  • Flat Latin-1 string values emit exact canonical JSON directly into final output storage.
  • Canonical/ASCII/BMP/astral/lone-surrogate and all JSON escape classes remain exact.
  • A fail-first allocation witness proves a pre-capacitated flat write allocates no transcode buffer.
  • JSON-focused normal/TSan/OOM tests, exact-parent Test262 JSON accounting, full units, and deterministic tier fuzzing pass with zero regressions.
  • Exact allocation evidence is recorded without an unmeasured throughput claim.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions