f1ac647125
FadeThroughStack(lazy: true) builds only the shown page first and the rest one per frame once no animation runs. Opening a run detail no longer lays out Timeline, Artifacts and Changes offstage during the route transition (transition build 62-103 ms -> 38-59 ms); first tab switches are unchanged. Adds tool/perf/interaction_bench.mjs (FrameTiming per interaction over the full-app fixture, CPU profiles mapped to Dart files), fixture options for hits/chats/graph, and notes/perf-round3.md with the survey.
123 lines
6.3 KiB
Markdown
123 lines
6.3 KiB
Markdown
# Performance round 3: survey and lazy run-detail tabs
|
|
|
|
This round started from measurements. It follows `notes/chat-stream-perf.md`,
|
|
`notes/chat-open-perf.md` and `notes/perf-glass-chrome.md`.
|
|
|
|
## Tools
|
|
|
|
- `tool/perf/interaction_bench.mjs` runs scripted interactions over the release
|
|
full-app fixture (`tool/search_selection_probe_entry.dart`) at 560x900,
|
|
Material, light theme. It clicks points, so Flutter semantics stay off. It
|
|
records Flutter FrameTiming (`tool/perf/frame_log.dart`, `?perf=1`) and
|
|
prints medians: build sum and max, raster sum and max, and the longest frame.
|
|
`--frames` prints every frame. `--cpuprofile` together with a
|
|
`--profile --source-maps` build assigns V8 samples to Dart files
|
|
(`tool/perf/cpu_attribution.mjs`).
|
|
- `tool/perf/perf_fixture.dart` adds fixture data: `?hits=N` Search hits,
|
|
`?chats=N` chats (each opens a short markdown transcript), and `?graph=1` (run
|
|
7 includes its graph).
|
|
- `tool/perf/js_size_by_source.mjs` splits main.dart.js by Dart source.
|
|
|
|
Headless Chrome has no GPU, so CanvasKit rasterises on the CPU and raster time
|
|
dominates every frame (see the glass note: with the GPU, frames take about
|
|
2-3 ms). Build time is the part that the app's code controls.
|
|
|
|
## Survey (base `main` ec619234, medians of 5)
|
|
|
|
Ranked by the worst build frame (ms):
|
|
|
|
| interaction | build max | build sum | longest frame |
|
|
| --- | --- | --- | --- |
|
|
| Chat tab, first visit, 150 chats | 116.5 | 189 | 143 |
|
|
| Settings, from Pipelines | 33.6 | 65 | 46 |
|
|
| Run detail open, with graph preview | 27-30 | 83-91 | 60-67 |
|
|
| Run detail open (runs list, 2 or 400 runs) | 24-29 | 72-90 | 55-66 |
|
|
| Search, typing `release` (209 hits) | 27.5 | 127 (24 frames) | 48 |
|
|
| Chat tab, first visit, 30 chats | 27-35 | 74-83 | 52-58 |
|
|
| Pipeline detail open | 16-22 | 55-66 | 56-60 |
|
|
| Run graph full screen | 20.8 | 35 | 65 |
|
|
| Chat list to open chat (20 messages) | 20.3 | 75 | 61 |
|
|
| Run Timeline tab, 400 steps | 17-25 | 36-46 | 33-44 |
|
|
| Main tab switch (Runs/Pipelines/Search) | 15-19 | 50-60 | 40-46 |
|
|
| Visit page from Timeline | 12-20 | 36-49 | 54-59 |
|
|
| Run page tabs (Summary/Artifacts/Changes) | 10-18 | 28-37 | 35-40 |
|
|
| Pipeline Graph and Source tabs | 8-16 | 27-37 | 37-42 |
|
|
| Artifact viewer open (the fixture serves no file) | 4.3 | 10 | 29 |
|
|
| Startup | 9.4 | 37 (15 frames) | 27 |
|
|
|
|
Startup: the first rasterised frame comes 300-400 ms after navigation with a
|
|
warm cache and about 1.5 s cold. A cold load spends about 1.15 s fetching and
|
|
compiling canvaskit.wasm. main.dart.js is 4.0 MiB (1.2 MiB gzipped), and app
|
|
code is about 15% of it (chat 171 KiB, the largest feature). Deferred loading
|
|
would save well under 100 KiB gzipped per feature, so it is not worth doing.
|
|
The icon fonts are already tree-shaken (MaterialIcons 1.6 MB to 18 KB).
|
|
Startup does no heavy synchronous work.
|
|
|
|
## Fix: lazy run-detail tabs
|
|
|
|
Profiling showed that opening a run detail built and laid out every page tab
|
|
offstage (Timeline, Artifacts, Changes) during the route transition, because
|
|
`FadeThroughStack` mounts all of its children. `FadeThroughStack(lazy: true)`
|
|
now builds only the shown page at first. It builds the rest one per frame once
|
|
no animation is running (no transient frame callbacks, so after the route
|
|
transition), or at once when one is shown first. After that, every page stays
|
|
mounted, as before. Only `RunDetailTabs` sets `lazy`. Making pipeline detail
|
|
and visit-page sections lazy gave no difference beyond noise, so those stay as
|
|
they were.
|
|
|
|
Before and after, `runs->run detail`, three runs each with `--frames`. Each
|
|
cell is the build time of the frames during the route transition (the first
|
|
9 frames):
|
|
|
|
| | before | after |
|
|
| --- | --- | --- |
|
|
| transition build sum | 62-103 ms | 38-59 ms |
|
|
| worst transition build frame | 20.7-54.1 ms | 16-34 ms |
|
|
|
|
Medians of 5, two rounds alternating with `main`:
|
|
|
|
| | before | after |
|
|
| --- | --- | --- |
|
|
| open: build max | 25.6 / 26.4 | 22.9 / 19.2 (now an idle prebuild frame) |
|
|
| open, 400 runs: build max | 28.9 / 28.5 | 21.0 / 22.5 |
|
|
| open with graph preview: build max | 25.3 / 28.2 | 21.2 |
|
|
| first switch to Timeline: build max | 13.0 / 9.8 | 14.1 / 16.3 (noise) |
|
|
| first switch to Timeline, 400 steps | 17.5 / 17.3 | 18.0 |
|
|
| Artifacts, Changes switches | 14.6-16.1 | 9.4-15.1 |
|
|
|
|
The build sum for the open window goes up by about 10 ms, because the pages
|
|
built later now take frames of their own. Those frames come after the
|
|
transition, while nothing animates. A first attempt that built pages only when
|
|
shown made the open cheaper (build max about 16 ms), but it moved the cost to
|
|
the first switch to Timeline (build max 17 to 24 ms, 400 steps 21 to 28 ms).
|
|
The idle prebuild avoids that.
|
|
|
|
Behaviour: no visible change. Within the first frames after a run detail
|
|
opens, a tab the operator has not shown is not mounted yet. Its offstage
|
|
widgets (for example the artifact gallery's thumbnails) therefore start a few
|
|
frames later. If an animation runs without stopping, unshown tabs are built
|
|
when they are first shown.
|
|
|
|
## Candidates for round 4
|
|
|
|
1. Chat list rows (largest value). `MaterialSessionList` and
|
|
`CupertinoSessionList` build every row of an open section in a `Column`
|
|
inside `CollapsibleListSection`'s `AnimatedSize`. The first Chat visit costs
|
|
about 0.75 ms of build per chat: 35 ms at 30 chats and 116 ms at 150, which
|
|
is a dropped-frame burst during the tab fade. Moving to slivers (heading
|
|
plus a lazy `SliverList`) fixes the scaling, but the section's size
|
|
animation has to be rebuilt, both for open and close (explicit
|
|
`Align.heightFactor`) and for rows arriving into an open section. Without
|
|
that it is a visual change, so it needs its own careful item.
|
|
2. Settings (33 ms build frame). Everything sits in one `SingleChildScrollView`
|
|
(about 1350 px of content). A lazy list would dispose offscreen sections that
|
|
own controllers, so it needs keep-alives or lifted state. Medium value: the
|
|
page is opened rarely.
|
|
3. Run detail open, other costs (about 15-20 ms left): the header plus Summary,
|
|
and `detailTimeline` and other step derivations that `_body` still runs for
|
|
unbuilt tabs on every rebuild. Builders instead of child widgets would
|
|
remove that work. Low to medium value.
|
|
4. Search result frame (27 ms for the first page of rows). Low value.
|
|
5. Cold start: canvaskit.wasm makes up most of the 1.5 s cold first frame.
|
|
Only caching and service-worker policy could help. Out of the app's control.
|