Profile mobile chat text rendering

This commit is contained in:
2026-11-07 22:03:52 +00:00
parent b08d458c4b
commit 11e25f6a5f
3 changed files with 95 additions and 4 deletions
+81
View File
@@ -0,0 +1,81 @@
# Mobile chat text profile
## Scope
Diagnostic-only profile of the real `ChatThreadView` with its isolated fake
`ApiGateway` (`tool/chat_composer_probe_entry.dart`). The synthetic transcript
contains prose, headings, inline emphasis/code, fenced Dart, links, lists and a
3-column Markdown table; the stream adds 80 incremental text updates. This is a
focused widget fixture rather than a full shell/session-list capture. Runs were
made in a quiet worktree on release web, headless Chrome at 560x1000 with
software rasterisation. These are Chrome wheel/software-raster comparison
numbers, not Android FPS; no authorized Android device was connected.
## Reproduction
From `app/`, after checking that no competing Flutter build, test or capture was
running:
```sh
/Users/alan/development/flutter/bin/flutter build web --release \
--target tool/chat_composer_probe_entry.dart \
--output build/mobile-chat-text-profile
node --check tool/chat_perf_probe.mjs
node tool/chat_perf_probe.mjs build/mobile-chat-text-profile 20 80 3 \
> build/mobile-chat-text-profile-short.json
node tool/chat_perf_probe.mjs build/mobile-chat-text-profile 300 80 3 \
> build/mobile-chat-text-profile-long.json
```
Each repetition uses fresh pages for open, 120 wheel gestures (60 up/60 down),
and streaming. The JSON reports are in the ignored build directory. The probe
was changed only to make the phone-width/repeat count explicit; the fixture was
extended with the table above.
## Measurements
Values below are medians across three repetitions. Frame timings are Flutter
`FrameTiming` values. `over16` is the count of measured frames over 16 ms in the
software Chrome harness, not a device refresh-rate assertion.
| workload | frames | build p50 / p90 ms | raster p50 ms | total p50 / p90 ms | over16 |
| --- | ---: | ---: | ---: | ---: | ---: |
| open, 20 messages | 13 | 2.6 / 4.3 | 26.2 | 29.6 / 31.8 | 13 |
| open, 300 messages | 15 | 2.5 / 4.3 | 25.7 | 29.3 / 32.5 | 15 |
| scroll, 20 messages | 120 | 1.4 / 6.7 | 25.0 | 28.0 / 36.0 | 120 |
| scroll, 300 messages | 245 | 1.5 / 6.8 | 24.7 | 27.6 / 35.9 | 245 |
| stream, 20 messages | 165 | 1.3 / 3.7 | 24.7 | 27.6 / 30.1 | 165 |
| stream, 300 messages | 160 | 4.8 / 5.8 | 24.8 | 29.4 / 32.0 | 160 |
## Ranked findings
1. **Measured: raster dominates this scrolling harness.** Build p50 is 1.4–1.5
ms while raster p50 is about 25 ms. These numbers cannot identify whether
text, tables, selection, or CanvasKit compositing owns the raster cost, so
they do not justify a Markdown rewrite.
2. **Measured: the long live answer costs more build time.** Stream build p50 is
4.8 ms for 300 messages versus 1.3 ms for 20. This is consistent with the
growing live Markdown turn and text layout, but it is not isolated proof that
Markdown parsing alone is responsible.
3. **Measured: opening history is not strongly message-count-sensitive here.**
Open build and total medians are effectively unchanged from 20 to 300 rows.
The transcript uses the existing row construction and `ChatMarkdownCache`;
this does not prove all native-device layout costs are equivalent.
4. **Evidence-backed next candidate, not a defect finding:**
`ChatMarkdownView` renders tables with `IntrinsicColumnWidth`, so a focused
visible-table A/B profile is warranted. It was included in this workload but
not isolated from the rest of rich Markdown.
## Next small experiment
Use the existing full-app `tool/perf/perf_fixture.dart` rich-chat fixture to
isolate table-free versus table-rich visible answers, repeating touch and wheel
separately at 560px. Then compare the same workload on an authorized native
Android device before making a mobile performance claim. A diagnostic selection
on/off comparison may follow only if the table experiment does not explain the
raster cost; selection behavior must remain unchanged.
No production code or behavior was changed. Selection/copy, rich Markdown,
scroll anchors and drafts remain unchanged. No app tests were run because this
visit changed only profiling fixture/probe code and a note; `node --check` and
the release build succeeded.
+4
View File
@@ -23,6 +23,10 @@ String _answer(int index) =>
'```dart\n'
'${List.generate(30, (line) => 'final v$line = $index * $line;').join('\n')}'
'\n```\n\n'
'| check | result | owner |\n'
'| --- | --- | --- |\n'
'| unit tests | passed | worker $index |\n'
'| static analysis | passed | worker $index |\n\n'
'- one\n- two\n- three\n';
/// The fixture history; the newest message is the operator's, so a streamed
+10 -4
View File
@@ -4,7 +4,7 @@
// flutter build web --release --target tool/chat_composer_probe_entry.dart \
// --output build/chat-perf
// then:
// node tool/chat_perf_probe.mjs build/chat-perf [messages=300] [deltas=200]
// node tool/chat_perf_probe.mjs build/chat-perf [messages=300] [deltas=200] [repeats=3]
//
// Three phases, each on a fresh page: open the transcript (the frames that do
// work after the history reply), wheel-scroll it up and back down,
@@ -17,13 +17,14 @@ import { openBrowser } from './capture/browser.mjs';
import { flutterPage } from './capture/page.mjs';
import { serveBuild } from './capture/serve.mjs';
const [dir, messagesArg = '300', deltasArg = '200'] = process.argv.slice(2);
const [dir, messagesArg = '300', deltasArg = '200', repeatsArg = '3'] = process.argv.slice(2);
if (!dir) {
console.error('usage: node tool/chat_perf_probe.mjs <build dir> [messages] [deltas]');
process.exit(2);
}
const messages = Number(messagesArg);
const deltas = Number(deltasArg);
const repeats = Number(repeatsArg);
function stats(frames) {
const pick = (i) => frames.map((f) => f[i]).sort((a, b) => a - b);
@@ -67,7 +68,7 @@ async function phase(origin, query, drive) {
});
const opened = Date.now();
try {
await page.open(`${origin}/?${query}`, { width: 880, height: 1000 });
await page.open(`${origin}/?${query}`, { width: 560, height: 1000 });
} catch (error) {
throw new Error(`${error.message}; page errors: ${JSON.stringify(page.errors.slice(0, 5))}`);
}
@@ -89,6 +90,8 @@ async function phase(origin, query, drive) {
const server = await serveBuild(dir);
try {
const results = [];
for (let repeat = 0; repeat < repeats; repeat++) {
const open = await phase(server.origin, `perf=${messages}`, async ({ opened }) => {
// The fixture flushes the timings 2.5 s after the history reply.
const end = Date.now() + 20000;
@@ -124,7 +127,10 @@ try {
return { streamed: marks.includes('PERF_STREAM_END'), stream: stats(stop()) };
},
);
console.log(JSON.stringify({ build: dir, messages, deltas, open, scroll, stream }, null, 2));
results.push({ repeat: repeat + 1, open, scroll, stream });
console.log(JSON.stringify({ repeat: repeat + 1, messages, deltas, open, scroll, stream }));
}
console.log(JSON.stringify({ build: dir, messages, deltas, repeats, results }, null, 2));
} finally {
await server.close();
}