mirror of
https://github.com/element-hq/synapse.git
synced 2026-11-04 22:07:34 +00:00
The persist transaction sent its statements one at a time: about forty round trips for a new room, about twenty for a message. Every write whose result nothing reads is now queued: the batch inserts and upserts, the deletes and updates, the current state and membership batches, the sliding sync rows, threads and sticky events. Queued writes go out together ahead of the next read, or with the COMMIT, in the order the code issues them, so the statements run in the same order as before. What is left are the reads, each a round trip carrying the writes before it: the room's share lock, room depth, outliers, redactions, backward extremities and the cache stream's IDs. The partial state insert stays immediate: it turns a constraint violation into `PartialStateConflict`, so the queue is sent first, and a queued write's own violation cannot be taken for it. `upsert_one`, for out-of-band memberships, also stays immediate. `OwnedColumn::copy` and `owned_params!` copy borrowed values into ones a queued statement can own (`ToOwnedSql`), and `execute_batch_later` queues a statement per row. The new room's write transaction goes from 42 round trips to about 12. The E2EE monitor's room on jki.re goes from 102 to 79 round trips overall, a plain room from 90 to 63. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PVLsNh6akt4ifEizY4D1ta