Skip to content

Keep a chat's projected rows and composer height with its transcript (851-4335) - #1406

Merged
pondorasti merged 1 commit into
mainfrom
alexandru/851-4335-projection-state
Nov 18, 2026
Merged

pondorasti merged 1 commit into
mainfrom
alexandru/851-4335-projection-state

Conversation

@pondorasti

Copy link
Copy Markdown
Member

Part of 851-4335 (tab state in models), under 851-4331.

What changed

The macOS chat view kept its projected transcript rows, their version, the publication state, the projection worker and the composer height as view state. That state died with the view, so reopening a tab started from empty rows and projected again.

It now lives with the chat's cached transcript surface:

  • TranscriptSettledProjection (TranscriptKit, unit tested) owns the rows, their version, the publication state and the worker. Submitting the request that is already published keeps the rows and drops any newer projection that is still running.
  • TranscriptComposerMetrics holds the composer height, so every view of one transcript asks for the same rows.
  • The chat view no longer cancels the projection when it goes away: a projection that finishes after the view left is kept for the next time the chat is shown.

No visual change.

Why

This is the first piece of chat state the reused chat view needs (851-4336 spike): with the rows in view state, re-pointing a chat view took three update passes (old chat's rows pushed into the new transcript, cleared, reloaded). It also helps today's deck on its own.

Numbers

Debug build, 500-turn chats, main-thread work per switch, same script before and after, fresh launch:

Switch Before After
Hotkey step between neighbouring chats 32 ms 28-30 ms
Reopen a chat whose tab was evicted (8 chats in rotation) 157-159 ms 106-109 ms
First visit to a chat ~190 ms ~185 ms

The machine was shared with other builds during both runs, so treat the neighbour-step difference as noise.

Notes for review

  • Skipping a request that is already published relies on equal requests meaning equal rows. TranscriptRowProjectionCache already relies on the same thing (it returns cached rows for an equal key without looking at the input).
  • A surface is bound to one controller, and the surface cache replaces it when the controller is replaced, so published rows never outlive their controller.
  • Rows are now retained per cached transcript (attached ones plus up to six detached) instead of per mounted view.
  • iOS keeps its own copy of this state for now; it can adopt TranscriptSettledProjection later.

Tophat (dev app, TRANSCRIPT_STRESS=1)

  • Switched between chats with the hotkey step and by jumping across eight chats: transcript, title and sidebar highlight follow, scroll position is kept.
  • Streaming chat: text that arrived while the chat was in the background, and after its tab was evicted, is shown on return; a turn that finished while the tab was evicted shows settled on return.
  • Sent messages: user bubbles and the error card appear.
  • Composer: a six-line draft grows the composer and the transcript makes room; the draft stays with its chat across a switch and the other chat keeps its own composer height.
  • swift test --filter TranscriptSettledProjectionTests (3 tests; each fails when the behaviour it names is removed), swift:format:check, swift:lint.

🤖 Generated with Claude Code

…(851-4335)

The chat view held its projected transcript rows, their version, the
publication state, the projection worker and the composer height as view
state, so they were thrown away with the view and rebuilt from empty each
time a tab was reopened.

They now live with the chat's cached transcript surface:

- TranscriptSettledProjection (TranscriptKit) owns the rows, their version,
  the publication state and the worker. Submitting the request that is
  already published keeps the rows and drops any newer projection still
  running.
- TranscriptComposerMetrics holds the composer height, so every view of one
  transcript asks for the same rows.

Reopening an evicted tab no longer starts from empty rows: about 158 ms to
about 107 ms of main-thread work on the Debug bench. It is also the first
piece of chat state a reused chat view needs to switch chats in one pass.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant