Skip to content

id(web): measure ProseMirror JSON-payload cost inside the MessagePack collab wire; evaluate binary/compression #1796

Closed

Description

@dezren39

Split from rollup #1294 (TODO.md backlog), triage task 2544, judged at main HEAD e561ab5.

Finding

The collab wire envelope is already binary MessagePack arrays with type tags (pkgs/id/src/web/collab.rs module docs: "Wire Protocol (MessagePack arrays)"), but ProseMirror doc/step payloads still travel as serde_json::Value inside those arrays (collab.rs data: serde_json::Value, steps: Vec<(Step, serde_json::Value)>). The TODO's measurement question is therefore only half answered.

Scope

Measure the JSON-payload cost (wire size, client/server CPU, latency) for representative editing sessions; evaluate true-binary encoding or compression of the step payloads; implement only if the measurement shows a material win.

Acceptance criteria

  • A measurement note (numbers, method, session shapes) is recorded on this issue.
  • A decision is recorded: keep JSON payloads (with the numbers as justification) or implement binary/compressed payloads (with the change linked).

Activity

  1. added
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Oct 28, 2026
  2. developing-today commented on Oct 28, 2026

    @developing-today
    Contributor
  3. added
    kind/performancePerformance problem or optimization
    source/queue-workerFiled or worked by the queue/worker pilot
    priority/lowNice to have; do when convenient
    effort/mMedium: expected under 1 day of work
    meta/enrichedIntake review done: acceptance criteria, links, and normalized labels added
    on Oct 28, 2026
  4. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    Intake review

    🤖 Agent note · filed

    • Agent: fleet monitor
    • Session / ID: repo-fleet-monitor run 2026-10-28 15:19 CDT
    • Found via: monitor reconciliation
    • Task: Intake enrichment — labels normalized, live status verified
    • Expectation: effort/m; done = labels + this review + meta/enriched applied
  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    task/triageQueue packet kind: verify, reproduce, and route this item
    and removed on Nov 3, 2026
  6. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: triaged (coverage pass)
    Coverage pass 2026-11-03: reviewed in the fleet-wide per-issue pass (drift / overlap / already-handled / stale / blockers / ordering). Verdict: still live; queued in repo-health-code-pilot as triage at priority 30 (priority/low). If this is already handled at current main, the triage closes it with evidence; if it needs splitting, the triage files the split.
    Found via: coverage pass 2026-11-03

  7. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

    • Agent: repo-worker-code (OpenChamber scheduled lane c8b9355e)
    • Queue task: 7731 (repo-health-code-pilot, triage, 20 min)
    • Plan: re-verify the serde_json::Value-inside-MessagePack shape at current main, measure wire cost for representative doc and step shapes, record the measurement + decision, then close or scope.
  8. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    Measurement: ProseMirror payload cost inside the MessagePack collab wire

    Judged at origin/main 1e3763faf. Code path re-verified at HEAD:

    • pkgs/id/src/web/collab.rs:511 — CollabMessage::encode is rmp_serde::encode::to_vec over tuples: [tag, version, doc, mode], [tag, version, steps, clientID], [tag, steps, clientIDs]. The ProseMirror doc / steps are serde_json::Value (collab.rs:466-478, :221).
    • pkgs/id/web/src/collab.ts:60 — the client is msgpackr Packr/Unpackr with useRecords: false: the same array layout, no record extensions.

    First correction to the premise: serde_json::Value does not mean JSON text on the wire. rmp-serde serializes a Value as native MessagePack (fixmap/map16 of string keys, str, int), so the payload is already binary. The relevant question is therefore not "JSON vs binary" but "how much of the binary frame is redundant text structure, and is compression worth it".

    Method

    MessagePack is deterministic, so I reproduced the exact rmp_serde layout (fixarray/array16, fixmap/map16, fixstr/str8/16/32, compact ints) and encoded the real envelope shapes the server produces. Deflate (zlib, level 6) was used as a conservative stand-in for zstd/brotli (no dictionary, no per-message tuning). Timings are single-shot on the laptop and are order-of-magnitude only.

    Doc shapes — synthetic ProseMirror documents built from the node/mark vocabulary the editor actually emits: paragraphs (plain, strong, em, link), headings (h2/h3), bullet lists, codeBlock, realistic word distribution. Sizes chosen to bracket real files: 6, 120 and 600 top-level blocks.

    Step shapes — replace (single-character typing), addMark over 30 chars, and client batches of 1/20/200/1000 steps. Batches are not hypothetical: the client already caps at MAX_STEPS_PER_MESSAGE = 1000 and MAX_STEPS_MESSAGE_BYTES = 1 MiB - 4 KiB and flushes multi-step batches (collab.ts:66-108).

    Results — Init (document) frame

    doc blocks MessagePack equivalent JSON text MP / JSON deflate ratio deflate / inflate
    6 11,935 B 16,362 B 72.9 % 1,269 B 9.4× 0.09 / 0.02 ms
    120 158,813 B 216,434 B 73.4 % 11,580 B 13.7× 1.42 / 0.22 ms
    600 796,780 B ~1.09 MB 73.4 % 54,703 B 14.6× 7.19 / 1.06 ms

    Byte composition of the Init frame (stable across sizes):

    • strings: 95.1–95.2 % of all MessagePack bytes
    • map keys alone: 42.0–42.7 %
    • text values: the remaining ~53 %

    Results — step frames

    frame MessagePack deflate saving
    1 typing step 89 B 92 B −3.4 % (framing wins)
    1 addMark (30 ch) 61 B 69 B −13 %
    20-step batch 1,467 B 316 B 78.5 %
    200-step batch 14,475 B 1,594 B 89.0 %
    1000-step batch 72,355 B 8,058 B 88.9 %

    Reading

    1. There is no JSON-text cost to remove. The envelope already delivers the payload at ~73 % of equivalent JSON text. A bespoke binary step encoding would save at most a few tens of bytes on an 89 B keystroke frame — below WS/TCP framing noise — while adding a second schema that must stay in lockstep with ProseMirror steps on the TS side (collab.ts packr path, stepWireSize/stepBatch). Not worth it.
    2. The cost is structural redundancy, not encoding format. 95 % of an Init frame is strings and 42 % is repeated map keys, which is exactly what a compressor eats: 13–14× on documents, 79–89 % on step batches ≥20.
    3. Where compression would pay: Init (first open and reconnect on long docs: 160 KB → 11.6 KB) and batched steps, which the client already produces for indents/pastes. Where it would not: single-keystroke Steps frames, where deflate is net negative.
    4. CPU is not the blocker. 1.4 ms to deflate a 159 KB Init, 0.22 ms to inflate; 7.2/1.1 ms at 797 KB. It is the protocol that costs: a capability handshake (the Auth/AuthOk exchange has room for it) plus a client-side inflate path, and the server-side max_message_size/frame-cap reasoning in frames.rs and collab.ts:74-84 assumes uncompressed step bytes — the client's byte budget would need to become a post-compression budget.
    5. Data limitation (the only real blocker on implementation): the repo has no telemetry for real Init frame sizes, so the prevalence of large documents is assumed, not measured. The synthetic shapes bound structure faithfully; they cannot tell us how often a session opens a 100 KB+ document. A 797 KB Init also sits uncomfortably close to the 1 MiB MAX_FRAME_BYTES the client mirrors, which compression would keep far below.

    Decision

    Keep the ProseMirror payloads as serde_json::Value inside the MessagePack envelope. No true-binary step encoding. The measurement shows the current shape is already within 27 % of the JSON baseline and that a custom encoding's per-keystroke saving is noise.

    Compression is deferred, not rejected, with an explicit revisit condition: if real Init frame sizes (p95, measured — not assumed) exceed roughly 100 KB, add negotiated compression on two paths only: Init, and Steps/Update frames above ~4 KiB of encoded steps. Do not compress single-step frames. Prerequisite: instrument the Init send/broadcast path with a byte-size log or metric (one line, no protocol change), and sequence any such change after the collab codec work in #1783, which touches the same module.

    No other blockers; the decision does not require a follow-up implementation task today, and this issue's two acceptance criteria are both satisfied by this note.

  9. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (triaged, closed)

    • Agent: repo-worker-code (OpenChamber scheduled lane c8b9355e)
    • Queue task: 7731 — completed, outcome triaged, no code change
    • Result: measurement note with wire-size numbers + recorded decision "keep serde_json::Value payloads (already MessagePack), no true-binary step encoding; compression deferred with a measured revisit condition (real Init p95 > ~100 KB) and prerequisite (Init byte-size instrumentation), sequenced after id(web): collab codec cannot decode its own CursorRemove frames — CollabMessage::decode has no tag-6 branch #1783"
    • Evidence: collab.rs:511/466-478 at 1e3763faf, collab.ts:60/66-108; Init 11,935–796,780 B (72.9–73.4 % of JSON text), deflate 9.4–14.6× on Init, 78.5–89.0 % on step batches ≥20, net-negative on single-step frames
    • Follow-up: none queued today; instrumentation is the gating prerequisite if the revisit condition is met
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/mMedium: expected under 1 day of workkind/performancePerformance problem or optimizationmeta/enrichedIntake review done: acceptance criteria, links, and normalized labels addedpriority/lowNice to have; do when convenientqueue/queuedHas a queued queue tasksource/queue-workerFiled or worked by the queue/worker pilottask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions