You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
Still live: filed this hour as a split from rollup id: TODO.md backlog rollup — small ideas not yet covered elsewhere #1294 (queue triage task 2544, judged at main HEAD e561ab5); the ProseMirror JSON-inside-MessagePack payload shape in pkgs/id/src/web/collab.rs is current at HEAD. No measurement has been recorded anywhere. Confirmed live.
Notes: measurement-first by design — the acceptance criteria require numbers and a recorded decision before any implementation. Do not let this morph into an encoding rewrite without the measurement note.
Risks: benchmark shapes decide the answer; unrepresentative sessions (tiny docs, no step bursts) would understate JSON cost. Include a large-doc, multi-editor session shape.
Suggested approach: instrument wire sizes on representative sessions first; only if JSON payload share is material, prototype compression (cheaper than a binary step encoding) and compare CPU trade-off.
🤖 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
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
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.
Measurement: ProseMirror payload cost inside the MessagePack collab wire
Judged at origin/main1e3763faf. 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 msgpackrPackr/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
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.
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.
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.
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.
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.
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
Activity
developing-today commentedon Oct 28, 2026
CODE-736
dezren39 commentedon Oct 28, 2026
Intake review
pkgs/id/src/web/collab.rsis current at HEAD. No measurement has been recorded anywhere. Confirmed live.🤖 Agent note · filed
dezren39 commentedon Nov 3, 2026
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
dezren39 commentedon Nov 3, 2026
🤖 Agent note · picked up
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.dezren39 commentedon Nov 3, 2026
Measurement: ProseMirror payload cost inside the MessagePack collab wire
Judged at
origin/main1e3763faf. Code path re-verified at HEAD:pkgs/id/src/web/collab.rs:511—CollabMessage::encodeisrmp_serde::encode::to_vecover tuples:[tag, version, doc, mode],[tag, version, steps, clientID],[tag, steps, clientIDs]. The ProseMirrordoc/stepsareserde_json::Value(collab.rs:466-478,:221).pkgs/id/web/src/collab.ts:60— the client ismsgpackrPackr/UnpackrwithuseRecords: false: the same array layout, no record extensions.First correction to the premise:
serde_json::Valuedoes not mean JSON text on the wire. rmp-serde serializes aValueas 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_serdelayout (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),addMarkover 30 chars, and client batches of 1/20/200/1000 steps. Batches are not hypothetical: the client already caps atMAX_STEPS_PER_MESSAGE = 1000andMAX_STEPS_MESSAGE_BYTES = 1 MiB - 4 KiBand flushes multi-step batches (collab.ts:66-108).Results — Init (document) frame
Byte composition of the Init frame (stable across sizes):
Results — step frames
addMark(30 ch)Reading
collab.tspackr path,stepWireSize/stepBatch). Not worth it.Auth/AuthOkexchange has room for it) plus a client-side inflate path, and the server-sidemax_message_size/frame-cap reasoning inframes.rsandcollab.ts:74-84assumes uncompressed step bytes — the client's byte budget would need to become a post-compression budget.MAX_FRAME_BYTESthe client mirrors, which compression would keep far below.Decision
Keep the ProseMirror payloads as
serde_json::Valueinside 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.
dezren39 commentedon Nov 3, 2026
🤖 Agent note · done (triaged, closed)
triaged, no code changeserde_json::Valuepayloads (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"collab.rs:511/466-478at1e3763faf,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