From 78bb5dcd9bfb37d9a30ec042de197fcacb7b19ce Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sun, 8 Nov 2026 00:11:13 +0000 Subject: [PATCH] Construct chat row contents only when slivers mount them --- .../chat/conversation/chat_thread_view.dart | 27 +++++++---- app/notes/chat-visible-row-construction.md | 47 +++++++++++++++++++ .../chat_floating_chrome_test.dart | 4 +- 3 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 app/notes/chat-visible-row-construction.md diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index bf1740e6..87e7eae2 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -1094,17 +1094,24 @@ class _ChatThreadViewState extends State { Padding( key: ValueKey(keys[index]), padding: const EdgeInsets.symmetric(horizontal: 16), - child: _entering( - rows[index], - _transcriptRow( + // Slivers mount only visible rows. Defer constructing + // their chips and checking cached widgets until then, + // rather than visiting the entire history per delta. + child: Builder( + builder: (_) => _entering( rows[index], - keys[index], - onDismissCompaction: - compactionNotice != null && - chatNoticeActivityCondition(rows[index]) == - compactionNotice.condition - ? () => _dismiss(compactionNotice) - : null, + _transcriptRow( + rows[index], + keys[index], + onDismissCompaction: + compactionNotice != null && + chatNoticeActivityCondition( + rows[index], + ) == + compactionNotice.condition + ? () => _dismiss(compactionNotice) + : null, + ), ), ), ), diff --git a/app/notes/chat-visible-row-construction.md b/app/notes/chat-visible-row-construction.md new file mode 100644 index 00000000..54657d50 --- /dev/null +++ b/app/notes/chat-visible-row-construction.md @@ -0,0 +1,47 @@ +# Chat visible-row construction + +## Finding and change + +Every transcript delta projected the history and eagerly called `_transcriptRow` +for every row, creating permission/question chip inputs and walking cached row +content even when the row was far outside the viewport. Sliver layout was +already lazy, but this construction work happened before slivers could skip it. +A row-local `Builder` defers that construction until the sliver mounts the row. +All rows, row keys, split anchors, selection, disclosures and Markdown rendering +remain in the existing path. No Markdown subset, font or table layout changed. + +## Controlled comparison + +Release web `tool/chat_composer_probe_entry.dart`, software Chrome at 560x1000, +300 history messages, the same 80 streamed text updates, and 120 wheel gestures. +Alternating baseline/candidate/baseline/candidate, each with fresh phase pages. +Baseline is 7ce4b1e6 (7287ba35 plus the preserved profiling tooling); candidate +diff is the row-local Builder only. Other lanes held compiles/tests/captures +for the four measured runs. Preliminary contended measurements were excluded. + +Means of the two per-run statistics, milliseconds: + +| phase | baseline build mean / p90 | candidate build mean / p90 | baseline / candidate raster mean | +| --- | --- | --- | --- | +| open | 2.41 / 4.45 | 2.15 / 3.40 | 25.34 / 26.05 | +| wheel scroll | 2.21 / 6.55 | 2.25 / 6.70 | 21.32 / 21.30 | +| stream | 3.21 / 5.95 | 2.27 / 3.80 | 21.08 / 21.09 | + +Streaming build mean is about 29% lower and build p90 about 36% lower here. +Scroll and software-raster cost are effectively unchanged. This is a focused +widget fixture, not full-shell timing or Android FPS evidence. Native hardware +was unavailable. The change reduces a measured source of streaming overhead; +it does not explain or claim to eliminate all perceived chat heaviness. +Raw JSON and summary are in ignored `app/build/perf-evidence/` and the private +`/tmp/chat-perf-quiet/` capture output. + +## Checks + +Conversation + transcript suite: 644 passed, one stale narrow Cupertino label +assertion failed (`/tmp/memwatch/out.AEK2gT`). That assertion required visible +permission text, conflicting with the user's shipped icon-only header. Updated +it to require no visible label while retaining current-value semantics and the +permission-sheet interaction. Its complete 10-test file passed after the change +(`/tmp/memwatch/out.xWOzXj`). Analyzer clean (`flutter-analyze.uyyFoA`). +The existing suite covers long-history lazy mounting, paging/anchors, live +updates, selection/copy, horizontal code/table scrolling and disclosure retention. diff --git a/app/test/features/chat/conversation/chat_floating_chrome_test.dart b/app/test/features/chat/conversation/chat_floating_chrome_test.dart index 9a4a98b0..626a9490 100644 --- a/app/test/features/chat/conversation/chat_floating_chrome_test.dart +++ b/app/test/features/chat/conversation/chat_floating_chrome_test.dart @@ -232,7 +232,7 @@ void main() { }); testWidgets( - 'Cupertino narrow header displays the current permission value', + 'Cupertino narrow header exposes the current permission on its icon', (tester) async { if (!cupertino) return; final semantics = tester.ensureSemantics(); @@ -254,7 +254,7 @@ void main() { expect(mode, findsOneWidget); expect( find.descendant(of: mode, matching: find.text('Ask for permission')), - findsOneWidget, + findsNothing, ); expect( tester.getSemantics(mode).label,