116 lines
5.8 KiB
Markdown
116 lines
5.8 KiB
Markdown
# Performance tools
|
|
|
|
Benches and fixtures for the full-app fixture
|
|
(`tool/search_selection_probe_entry.dart`) and widget-test benchmarks in
|
|
`test/perf/`. Each script's header documents its own options.
|
|
|
|
## Design budget: run it for every new design
|
|
|
|
Every `AppDesign` (Settings → Design) must cost about what Default costs. A
|
|
design agent runs both checks below before landing, and again after any change
|
|
to a design's theme or to code that reads `AppDesignTokens`. Both pick up new
|
|
`AppDesign` values on their own: no list to edit.
|
|
|
|
### 1. Widget-test budget (fast, deterministic, part of the test suite)
|
|
|
|
```sh
|
|
tool/memwatch/full.sh test/perf/design_bench_test.dart
|
|
```
|
|
|
|
Per design it checks and prints (`BENCH <design> {...}` in the log):
|
|
|
|
- `light()`/`dark()` return the same cached `ThemeData` for the same design and
|
|
font, and a theme rebuilt from scratch (`AppDesign.build`) equals the cached
|
|
one. A design whose theme holds an object without value equality (a
|
|
`Decoration`, a `ThemeExtension` without `==`) fails here: hoist it to a
|
|
constant or a per-brightness cache.
|
|
- `unrelatedThemeRebuilds` / `unrelatedFrames`: ten host rebuilds that do not
|
|
change the design rebuild no `Theme.of` dependent and start no theme
|
|
animation (one frame each).
|
|
- `switchFramesPerSwitch`: frames to settle a live design switch; after the
|
|
switches, no listener is left on the design controller.
|
|
- Scrolling a 120-row CLI transcript: `scrollRebuildsPerRow`,
|
|
`scrollLayersPerFrame` and `scrollSaveLayersPerFrame` (opacity, backdrop,
|
|
image/colour filter and shader-mask layers), plus the layer kinds.
|
|
- `themeBuildUs` (one uncached build) and `scrollFrameUs` are informational
|
|
only (debug-mode times).
|
|
|
|
It fails when a design's counts exceed Default's by more than 25% + 1.
|
|
|
|
### 2. Browser frame budget (real renderer, wasm/skwasm)
|
|
|
|
```sh
|
|
flutter build web --profile --wasm --no-web-resources-cdn --source-maps \
|
|
--target tool/search_selection_probe_entry.dart --output build/design-profile
|
|
CHROME_PATH=/usr/bin/chromium CAPTURE_ISOLATE=1 \
|
|
node tool/perf/design_bench.mjs --build build/design-profile --out /tmp/design
|
|
```
|
|
|
|
For every design (`window.__perfDesigns()`, `tool/perf/design_probe.dart`) it
|
|
runs, at 1280x800 dark with `chats=3&msgs=200&cli=1&rich=1` or 560x900:
|
|
|
|
| scenario | what |
|
|
| --- | --- |
|
|
| `scroll` | wheel a 200-message transcript up and back |
|
|
| `switch` | open chat 2, chat 3, chat 1 from the list |
|
|
| `runs` | wheel 400 runs |
|
|
| `graph` | open run 7's graph full screen and pan it |
|
|
| `design` | switch live to every other design and back, 10 rounds (`window.__perfDesign(id)`), with JS heap growth after GC |
|
|
|
|
It prints medians per design (frames, build/raster mean per frame, sums and
|
|
maxima, frames over 16 ms) and exits 1 when a design's mean build or raster
|
|
time per frame is above `--ratio` (1.35) x Default + `--slack` (1 ms). Means,
|
|
not sums: a cheaper design draws more frames in the same gesture. It also
|
|
fails when live switches grow the heap by more than `--leak` (8) MB, or
|
|
when a design makes an off-origin request (a font fallback fetch) that Default
|
|
does not. `--designs paper` limits the run (Default is always included),
|
|
`--only scroll,design` the scenarios, `--repeat` the repetitions (3), `--gpu`
|
|
keeps WebGL. Headless Chrome without `--gpu` rasterises on the CPU: compare
|
|
designs with each other, not with a device.
|
|
|
|
Click points assume the chat list's row positions at 1280x800 (chats at
|
|
y=170/260/335); a design that changes list density a lot should check
|
|
with `tool/capture` that those points still open the chats, and give the
|
|
step its own point keyed by design id (Compact: y=150/210/266).
|
|
|
|
The widget test budgets transcript rebuilds per row scrolled past
|
|
(`scrollRebuildsPerRow`), not per frame: a denser design shows more rows in
|
|
each 120px step for the same per-row cost. `scrollRebuildsPerFrame` stays
|
|
informational.
|
|
|
|
## Rules the budget enforces
|
|
|
|
- Build theme objects once: no `ThemeData`, `ColorScheme.fromSeed`, `TextStyle`
|
|
sets or decorations per build. Keep design facts in `AppDesignTokens` and read
|
|
them with `AppDesignTokens.of(context)` (a map lookup).
|
|
- Paint glyphs and frames with `CustomPainter`s whose `shouldRepaint` compares
|
|
their fields; no `saveLayer` (`Opacity` over content, `ShaderMask`,
|
|
`ColorFiltered`) per row.
|
|
- Blur only the app's bars and floating pieces, never list rows or bubbles:
|
|
`GlassPill.blurSigma` (4) is the most a piece may use, one
|
|
`BackdropFilter.grouped` per piece inside a `BackdropGroup`, and a solid
|
|
fill under high contrast and flat designs.
|
|
- Bundle every font a design needs (`pubspec.yaml` `fonts:` for always-used
|
|
families, on-demand assets otherwise). A design may not add network font
|
|
fetches; Default's own (Roboto and Noto Sans Symbols from fonts.gstatic.com,
|
|
fetched by the web engine) are the baseline.
|
|
|
|
## Known costs (December 2026 baseline)
|
|
|
|
Default is the heaviest design on the CPU raster path: its bars and floating
|
|
pieces blur what scrolls behind them (`GlassPill`, sigma 4), and its bubbles
|
|
add clip-path layers. Terminal and Paper draw flat pieces and come in at about
|
|
a third of Default's raster time per frame when scrolling a transcript. A
|
|
**Glass** design is gated against Default, which already blurs its bars, so it
|
|
has room for the same blur but not for more pieces: keep blur on the bars,
|
|
composer and floating pieces only (never rows, bubbles or the transcript),
|
|
sigma at most `GlassPill.blurSigma`, one grouped filter per piece, no blur
|
|
animating per frame (fade the fill, not the sigma), and solid fills under high
|
|
contrast. Run `design_bench.mjs` with and without `--gpu`; the CPU run is the
|
|
weak-device proxy.
|
|
|
|
A live design switch costs about 15 ms of build per frame for MaterialApp's
|
|
200 ms theme animation (about 12 frames of the whole app rebuilt with a lerped
|
|
theme), in every design. It is a deliberate blend, run only when the operator
|
|
picks a design.
|