bc00d321d9
A rebuilt Terminal theme never equalled the last one (AppDesignTokens, AnsiAccents and the tab indicator compared by identity), so any host rebuild (a detached window's title, a font notification) rebuilt every Theme.of dependent and ran MaterialApp's 200 ms theme animation. Themes are now cached per (design, brightness, font) and compare by value; chat colour seeded schemes are cached too. test/perf/design_bench_test.dart and tool/perf/design_bench.mjs check every registered AppDesign against Default (tool/perf/README.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
4.3 KiB
Markdown
89 lines
4.3 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: `scrollRebuildsPerFrame`,
|
|
`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 median build/raster sums and maxima per design and exits 1 when a
|
|
design's build or raster sum is above `--ratio` (1.35) x Default + `--slack`
|
|
(25 ms), 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.
|
|
|
|
## 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.
|