Chat sections are slivers: a lazy, keyed SliverList under the same heading, with SliverAnimatedExtent reproducing the clipped AnimatedSize for open, close and arriving rows. The first Chat tab visit no longer builds every row (150 chats: worst build frame 116 ms to 19 ms).
3.0 KiB
Performance round 4: lazy chat sessions list
Round 3's top candidate (notes/perf-round3.md): the first visit to the Chat
tab built every row of an open section at once, about 0.75 ms per chat.
Change
SliverCollapsibleListSection(lib/ui/layout/collapsible_list_section.dart) replaces the boxCollapsibleListSection, which only the chat list used: the same heading, then a lazySliverListof the section's entries (directory headers, rows, row refusals). Entries are keyed, with afindChildIndexCallback, so rows keep their elements when rows before them arrive or leave. Rows are still the round-2 memo (session_row_memo.dart).SliverAnimatedExtent(lib/ui/layout/sliver_animated_extent.dart) is the sliver form of the clipped, top-alignedAnimatedSizethat the section used: on open, close or a change of row count it moves the reported extent from what it showed to the child's new extent (Motion.standard,Motion.curve), drawing the child at once and clipping it. Closing leaves blank space that shrinks, as before. Reduced motion snaps.SliverRevealdid not fit: it scales the child's extent by a factor (so closing would show the rows shrinking, and arriving rows would not animate).MaterialSessionListandCupertinoSessionListareCustomScrollViews. Material reproducesListView's media-padding handling (vertical padding on the scroll view, side padding left to the rows); Cupertino keeps its explicit floating-bar padding. Shared entry building:session_list_items.dart.
Not animated any more: a row whose own height changes without the row count changing (for example a longer subtitle) now snaps instead of animating the section's height. Row counts, refusals (separate entries), open and close still animate.
Measurements (release, tool/perf/interaction_bench.mjs, medians of 5, two alternating rounds)
| scenario | metric | main 2f6d967f |
branch |
|---|---|---|---|
| Chat tab first visit, 30 chats | build max (ms) | 31.5 / 31.6 | 23.1 / 23.0 |
| build sum | 73.5 / 75.1 | 63.4 / 54.5 | |
| longest frame | 59.3 / 59.2 | 51.4 / 48.4 | |
| Chat tab first visit, 150 chats | build max | 117.3 / 114.0 | 18.9 / 18.4 |
| build sum | 185 / 180 | 54 / 56 | |
| longest frame | 127 / 140 | 45.2 / 45.8 | |
| Chat list to open chat (control) | build max | 20.3 / 18.1 | 20.3 / 22.9 |
The cost no longer scales with the number of chats. test/perf/list_and_gallery_bench_test.dart
(200 chats): rows built 200 to 12; total rebuilds over 50 running-state
changes 18850 to 9900.
Visual check
tool/capture over both release builds, ?chats=30, Material and Cupertino,
light and dark, 560x1000: top, scrolled 600 px, bottom, section closed and
reopened (20 pairs), plus the bench's settled shots at 30 and 150 chats and the
empty state. All byte-identical except the Cupertino scrolled pair, where
14 pixels at the ends of the transient scrollbar thumb differ: a lazy list
estimates its total extent until every row has been laid out (at the bottom
the shots are identical).