Repository navigation
perf(core): skip encoding durable event payloads that aren't persisted - #58923
Conversation
There was a problem hiding this comment.
The change looks sound. With persist off, the encoded payload was only used by the stale-replay comparison and the EventTable insert, which already run only with persist on, so skipping the encode doesn't change behaviour. With persist on, the encode still runs inside the transaction, so an encode failure still rolls it back. I checked that the new encode-count test fails on the base (3 encodes) and passes here. The bus, projector and title tests pass (103), and tsc -b in packages/core is clean.
Public API: unchanged (server internals only; no wire, event or schema change).
One small ask: the new test file is 137 lines for a 16-line change. Its first two cases (message seqs and the title path's sequence check) pass on the base too, because they cover code this PR doesn't touch. The test could be cut down to the encode-count case, which is the one that checks this change.
| .run() | ||
| return db | ||
| }) | ||
|
|
There was a problem hiding this comment.
These first two cases pass unchanged on the base, because they cover sequence behaviour this PR doesn't touch. They and seedSession could be dropped so the file is just the Counted encode-count case, which fails on the base and passes here.
What it does. Every durable event was schema-encoded on publish, even when
persistis off (the default) and the encoded payload was thrown away. This skips that work. Clients receive exactly what they did before.How it works.
commitDurableEventandpublishAll, the payload is encoded only where it's used: the stale-replay comparison and theEventTableinsert, both of which already run only whenpersistis on.event_sequenceread/upsert andevent.durable.seqare unchanged. They still run withpersistoff, because the session projector (session_message.seq, fork copy, current-assistant lookup),SessionTitle's optimistic check andSessionTransferdepend on them. Only the encode and payload are skipped.Risk. Server only, no data or wire change. With
persistoff, a payload that fails schema encoding no longer throws at publish. Nothing catches or relies on that throw, ephemeral events never had it, and projections that store data run their own encode.Proof.
packages/core/test/bus-unpersisted.test.ts, withpersistoff: message seqs still increase andBus.latestSequenceadvances; the title path's sequence check still accepts a fresh seq and rejects a stale one; an encode-counting schema counts 3 encodes on dev and 0 with this change.bun teston the bus, projector and title test files: 103 pass.bun run typecheckinpackages/core: clean.