Repository navigation
Keep long chats smooth by re-checking generated images only in changed turns - #52675
Conversation
…ows changed Tracked in STA-14945.
Unchanged history now reaches the generated-image projection with the same rows, so bot chats hit its per-turn cache too.
|
Performance scan (e6e02ff): pass, no new costs.
|
|
Status (e6e02ff): ready for merge once CI is green. Problem: in long chats, every transcript update re-checked all finished turns to place generated images, which made long chats stutter on phones while an agent worked. Change: finished turns keep their result and only changed turns are re-checked. Bot chats get the same saving because unchanged note rows now stay the same objects. Nothing looks different. Verified:
Benchmark: head=e6e02ff499a79ac0a890e907a381f40d6ff45b93 gate=PASS corpus=synthetic 40,000-row transcripts (2,000 turns, last turn streaming; plain and bot chats with item mail and folded notes), real image-projection and note-folding functions, base and head interleaved 3x: image step p50 12.6 → 1.6 ms (plain), 31 → 2.0 ms (bot); note folding unchanged within noise. Deferred: quadratic copying when folding very long runs of consecutive bot notes (pre-existing, unchanged here). No screenshots: there is no visual change. |
[Medium impact] The PR appears safe to merge; no actionable issue was found. SummaryThe PR reuses generated-image results for unchanged settled turns. It also preserves hidden and folded bot-row identities so bot chats can use that cache.
Reviews (1) · Last reviewed commit: "perf(bots): compare folded rows through ..." · Reviewed by Greptile |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
ELI5
In a long chat, every time the agent's reply moved forward, the app re-checked every earlier finished turn to decide where generated pictures belong. On phones this made long chats stutter while an agent was working. Now finished turns remember their answer, and only the turn that actually changed is checked again, including in bot chats. Pictures and bot notes show exactly as before.
What Changed
nativeChatGeneratedImageAnswersnow splits settled rows by turn and keeps each turn's projection in aWeakMapkeyed by the turn's first row. A turn is re-projected only when its rows' identities or the markdown image-source resolver change; otherwise its earlier replacements are reused. The per-turn classification logic itself is unchanged, just moved intoprojectTurn.foldBotItemNotesrebuilt hidden item-mail rows and merged note rows as new objects on every call, which would make bot-chat turns miss that cache every time. Hidden rows are now cached per source row, and a folded row equal to the one built last time (compared by reference a few levels down, never by serializing) is reused.Why
The projection ran over the whole history on every live update (desktop on each saved row, mobile on every transcript update). Reusing the result for unchanged turns keeps the same output while removing the repeated work; settled rows are immutable, so row identity is a safe cache key.
Linked Issue
Tracked in STA-14945.
Visual Proof
N/A: no visual change; images are placed exactly as before.
Testing
Platform-independent code shared by desktop and mobile; checked on macOS with a script that calls the real functions.
Performance
Less work per live update: only changed turns are re-classified; the remaining per-update cost is one identity walk over the rows. Memory is one small cache entry per settled turn and per folded row, released with its rows.
Risk
Level: Low. If a cache were wrong, a generated image or bot note could show stale; both reuse a result only when every input row (or every compared part) is the same object as before. Plain revert.
Review
Agent skill upstream boundary
Notes
Shared code: desktop and mobile both use it. No platform, SSH or saved-data impact.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)