Repository navigation
Commit b5aa4ec
perf(ios): virtualize the chat transcript on ChatLayout (#2178)
## Why
The transcript was an eager `VStack` in a `ScrollView`. Keeping the rows
in view still while older pages go in took layer after layer of patches,
and the iOS 27 paging jump (#2148) came out of them. Past 400 rows it
switched to a lazy stack, and scrolling down from there froze for
seconds. The transcript is now a `UICollectionView` laid out by
[ChatLayout](https://github.com/ekazaev/ChatLayout), which keeps the
position itself, with each row a SwiftUI view in its own cell. This
replaces #2164's patches, which are closed unmerged.
## Invariants
- Only the rows near the screen are built and measured. An older page
goes in as soon as it is fetched, and the rows in view do not move.
- A row that grows after it showed (a picture, a card filling in) moves
nothing in view. On the bottom, the newest row stays on the bottom while
it grows.
- Back to bottom, a jump to a quoted message or the unread line, and the
status-bar tap (to the oldest loaded message, as before) land where they
did.
## Scope
- New dependency: ChatLayout 2.5.2 via SPM, pinned to the exact version,
MIT license. It is a single custom `UICollectionViewLayout` with no
transitive dependencies.
- Removed: the `placingOlder` hold, the `ScrollHandle` offset shifts,
`eagerRowLimit` and the lazy switch, the `defaultScrollAnchor` roles,
`DistanceFromBottom`/`BottomMarker`, and the iOS 17 legacy path.
`TranscriptStore`, the row views and `ChatActions` are unchanged; older
pages now go in when they are fetched.
- Rejected: an inverted (flipped) list. It was spiked and worked, but
VoiceOver order, edge effects and insets all need flip workarounds.
ChatLayout keeps everything native.
- After a chat opens, the rows just above the screen are laid out and
drawn once off screen, one per frame, so the first fling up does not
build several cards in one frame.
- Left out: the thread overlay keeps its own list.
## Merge danger
Two-way door; a revert restores the old list. Blast radius: every chat
transcript (main Chat, topic chats, task chats).
## Evidence
- New hosted tests: a row above the screen that grows moves nothing in
view, a row below the screen that grows moves nothing in view, and the
newest row stays on the bottom while it grows in steps. An older page
lands without moving the rows in view (`PagingUpTests`, updated). The
scroll, store, cache, share and thread suites pass on an iOS 27.2
simulator.
- `ROME_PERF=paging` / `pagingdown` against #2164's head, same
simulator: a mid-screen row drifted 0 pt in every hold (11 holds paging
up, 9 coming down, against #2164's 0 pt kept rows). An older page goes
in in 4–11 ms including layout, against 45–78 ms. Scrolling down past
520 messages has a worst frame of 43–103 ms, against 150 ms. Flinging up
has a hitch rate of 10–14 ms/s, against 18–23, and a worst frame of
60–67 ms, against 110–125.
- Checked on the simulator: context-menu previews and Reply, share-mode
selection, keyboard and composer insets with interactive dismissal, back
to bottom, the typing row, task chats starting at the top, a live
Dynamic Type change, and dark mode. Light snapshots of the chat screens
match `main`, except for animation frames. VoiceOver order was not
checked with VoiceOver; without a flip it follows the rows' order.
- Tried on a phone against a dev stack.
- A question or widget card keeps its unsent answers and its sent lock
when its cell is reused: the list keeps each card's surface, known by
its row and its tool use id, which repeats across turns
(`WidgetSurfacesTests`). Each cell takes its row's identity, so a reused
cell starts fresh before iOS 18 too; no iOS 17 runtime was at hand to
watch that on.
## Follow-up (not blocking)
- Each list update hands the environment and footer to every visible
cell, so each streamed token redraws the rows in view, not only the
streaming one. `main` redraws every row per token, so this is no
regression, and the hand-off is also what brings fresh row closures to
cells on screen. Measure with `ROME_PERF=stream`, then pass only the
keys the rows read.
- An unfolded long reply folds again once its cell is reused.
- A jump to a row merged in the same update as the jump can be dropped
without a retry.
- A card coming back into view reads its binds again, which can reset an
unsent edit in a field the app fills. Read once per open, and again
after a press.
- `ThreadOverlay` keeps its own SwiftUI `ScrollView`; moving the thread
onto `TranscriptList` would leave one list.
- The cached row heights are never pruned within a chat's lifetime.
Fixes #2141
Fixes #2148
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 78beb24 commit b5aa4ec
19 files changed
Lines changed: 1257 additions & 762 deletions
File tree
- ios
- Rome.xcodeproj
- RomeTests
- Rome
- Demo
- Features/Chat
- Support
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | | - | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
54 | | - | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| 110 | + | |
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
| |||
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
| 179 | + | |
177 | 180 | | |
178 | 181 | | |
179 | 182 | | |
| |||
259 | 262 | | |
260 | 263 | | |
261 | 264 | | |
| 265 | + | |
262 | 266 | | |
263 | 267 | | |
264 | 268 | | |
| |||
563 | 567 | | |
564 | 568 | | |
565 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
566 | 578 | | |
567 | 579 | | |
568 | 580 | | |
| |||
581 | 593 | | |
582 | 594 | | |
583 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
584 | 601 | | |
585 | 602 | | |
586 | 603 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
85 | 94 | | |
86 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
87 | 123 | | |
88 | 124 | | |
89 | 125 | | |
| |||
0 commit comments