Ivan FB b7a65e3a02
perf(protobuf): parse the buffer once instead of rescanning per field
Addresses review feedback on PR #77: `getField` rescanned the whole
buffer on every call, giving O(fields × len) decode. Parse the message
once at `ProtoBuffer.init(data)` in a single forward pass with the
library's reader, indexing values by field number; the accessors are
then plain lookups (last-wins / repeated semantics fall out of wire
order). Public API and wire behaviour are unchanged.

The full type-driven `Protobuf.encode/decode` API is intentionally not
used here: it cannot express the backward-compatible causal-history
decode (field 3 is repeated HistoryEntry now, repeated bare-string IDs
in legacy messages), and its default-value omission would drop the
always-written empty fields the strict decoder requires (e.g. empty
`content` on sync messages), breaking compatibility with peers on the
current wire format.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 20:18:18 +02:00
..