Optimize streaming message projection path#1688
Optimize streaming message projection path#1688juliusmarminge wants to merge 1 commit intot3code/perf-checkpoint-reactor-fanoutfrom
Conversation
Co-authored-by: codex <codex@users.noreply.github.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
ApprovabilityVerdict: Approved Performance optimization that refactors streaming message persistence from JavaScript-based text concatenation to database-level upserts. The change is self-contained to the projection pipeline, includes comprehensive tests, and the author is the primary owner of this code. You can customize Macroscope's approvability policy. Learn more. |
Summary
getByMessageIdand streamingappendTextDeltaperformance.mdPerf impact
create-turn-spam-8xthread.create dispatch -> thread.created:3.61ms / 58.38ms->2.38ms / 20.36mscreate-turn-spam-8xthread.archive dispatch -> thread.archived:5.71ms / 50.80ms->0.97ms / 16.53msack -> eventforthread.createdropped from56.95msp95 to19.22msp95Testing
bun run --cwd apps/server test src/persistence/Layers/ProjectionThreadMessages.test.ts src/orchestration/Layers/ProjectionPipeline.test.tsbun run --cwd apps/server test:perfbun run fmt .bun run lintbun run typecheckStacked on the checkpoint-reactor PR.
Note
Medium Risk
Changes the message projection persistence/write path and SQL upsert semantics for streaming updates, which could affect message text/attachment consistency if edge cases are missed. Scope is limited to projection read-model storage and is covered by added repository tests.
Overview
Optimizes the
thread.message-sentprojection hot path for streaming messages. Instead of scanning all messages in a thread to find the current one, the pipeline now either appends streaming text via a new SQLappendTextDeltaoperation or does a direct per-message lookup (getByMessageId) before a finalupsert.The thread message projection repository API is extended with
getByMessageIdandappendTextDelta, with new SQL queries to support single-row lookup and conflict-based delta concatenation while preserving existingcreatedAt/attachments. Tests are added to cover the new lookup and streaming-delta behavior (including attachment/createdAt preservation).Written by Cursor Bugbot for commit 3bec3d2. This will update automatically on new commits. Configure here.
Note
Optimize streaming message projection by appending text deltas instead of reconstructing full rows
thread.message-sentevents now callappendTextDeltaon ProjectionThreadMessageRepository, concatenating incoming text onto existing rows via SQLCOALESCErather than upserting a full reconstruction.getByMessageIdto preservecreatedAtand retain prior attachments when the event omits them.getByMessageIdandappendTextDeltato the repository shape in ProjectionThreadMessages.ts with corresponding input schemas.Macroscope summarized 3bec3d2.