Skip to content

perf: report what changed on the message channel instead of re-deriving it in the renderer #2049

Closed

Description

@Astro-Han

Problem

Every refreshMessages ships the whole message log over IPC. Structured cloning hands the renderer entirely fresh objects, so nothing is reference-equal even when nothing changed — the renderer cannot tell which turns moved without reading every byte it just received.

createTranscriptProjection (#2034) does exactly that: reconcileTurnIdentities walks every turn's args and tool results and compares them by value. It is correct and it is worth its cost today, but it is the dominant remaining cost on the refresh path and it grows linearly with session length.

Measured on synthetic transcripts (5 messages per turn, an 8 KiB tool result per turn), structuredClone of the message array subtracted since both shapes pay it:

10 turns 40 turns 120 turns / 1.0 MB
reconcileTurnIdentities deep compare 0.05 ms 0.18 ms 0.44 ms
whole refresh path 0.21 ms 0.20 ms 0.49 ms

refreshMessages fires at step and tool boundaries, not per token, so this is not the #2030 stutter. It is a cost that scales the wrong way: a long session pays it repeatedly for a transcript that mostly did not change.

Why the renderer cannot do better on its own

Any "did this change" judgement over freshly deserialized objects is Ω(bytes) — you have to read what you were handed. A cheap digest does not escape it either: edit-and-resend keeps the same message id and timestamp while the text changes, so a digest that can tell those apart has to include the text, which is the value walk again.

The information does exist. The writer knows what it wrote; SQLite is already the sole operational authority (#1994) and rowids are right there. The IPC boundary is where it gets discarded, and the renderer then reconstructs it by brute force.

Options

Per-turn revision. Each turn carries a counter the writer bumps. The renderer compares integers instead of object graphs. Smallest change to the transport shape; the projection keeps its current structure and swaps its judge.

Incremental fetch (since sequence). The renderer says what it already has and receives only newer rows. Unchanged data is never serialized or sent, so it also removes the clone cost, not just the comparison — but it needs a story for edits and deletions of existing rows, which a monotonic sequence alone does not express.

Worth deciding between these before building; they are not the same size.

Blast radius

packages/storage → sessions-ipc-main.ts → the renderer's message store → createTranscriptProjection. Three packages, and it changes a data transport contract, which is why it was kept out of #2034 — that PR removes wasted recomputation on the receiving side, this removes wasted transport on the sending side. Same direction, separately reviewable.

Not urgent

The current cost is sub-millisecond and the correctness story is solid (32000-step differential fuzz against full re-derivation found no divergence). This is worth doing when session lengths make the linear term matter, or when someone is already in this layer — not as a standalone emergency.

One caution for whoever picks it up: the tempting shortcut is to relax valuesEqual instead (skip a field, save a walk). That fails twice over — the changed turn keeps its object identity and hits a stale entry in the presentation WeakMap that is keyed on it, so the failure mode is a silently frozen UI rather than an extra render.

Refs #2030, #2034.

Activity

  1. YayoiNanoka commented on Aug 17, 2026

    @YayoiNanoka
    Contributor

    Hi @Astro-Han, I’m reviewing older open issues and wanted to confirm the current disposition of this one.

    It looks like #2922 and #2937 implemented a broader version of the incremental-fetch option proposed here:

    • transcript storage and transport are now sequence- and watermark-based;
    • Desktop Main maintains a bounded sparse replica and fetches only missing ranges;
    • Main-to-Renderer IPC sends incremental upserts, evictions, and overlay completions;
    • message, tool, and terminal changes no longer trigger a complete transcript refresh.

    reconcileTurnIdentities still exists, but it now operates over the bounded resident window rather than the complete session history, so the original cost no longer grows with the full transcript.

    Would you consider #2049 fully addressed and safe to close? If not, is the remaining requirement specifically to remove the deep comparison inside the bounded Renderer window as well?

    点击展开中文

    你好 @Astro-Han,我正在整理较早的 open issue,想确认一下这个 issue 目前应该如何处理。

    看起来 #2922 和 #2937 已经实现了这里提出的增量读取方案,而且覆盖范围更完整:

    • transcript 的存储和传输现在基于 sequence 与 watermark;
    • Desktop Main 维护有界的 sparse replica,只读取缺失的范围;
    • Main 到 Renderer 的 IPC 只发送增量 upsert、eviction 和 overlay completion;
    • message、tool 和 terminal 变化不再触发完整 transcript 刷新。

    reconcileTurnIdentities 仍然存在,但它现在只处理有界的驻留窗口,而不是完整 session 历史,因此原来的成本已经不再随完整 transcript 长度增长。

    你认为 #2049 是否已经完整解决,可以关闭?如果还不能关闭,剩余要求是否仅仅是进一步删除 Renderer 有界窗口内的深度比较?

  2. Astro-Han commented on Aug 17, 2026

    @Astro-Han
    ContributorAuthor

    Thanks @YayoiNanoka, this is is done by previous PRs. Closing now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions