From e52392b332f82315817f464cb366a59df736dabd Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 3 Dec 2026 19:56:34 +0000 Subject: [PATCH] Design bench: budget per-frame means, document Glass limits A cheaper design draws more frames in the same gesture, so build/raster sums penalised it; the gate now compares mean build and raster time per frame with Default's. Co-Authored-By: Claude Opus 5.5 --- app/tool/perf/README.md | 27 ++++++++++++++++++++++++--- app/tool/perf/design_bench.mjs | 15 ++++++++++----- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/tool/perf/README.md b/app/tool/perf/README.md index f41ae585..121c373a 100644 --- a/app/tool/perf/README.md +++ b/app/tool/perf/README.md @@ -57,9 +57,11 @@ runs, at 1280x800 dark with `chats=3&msgs=200&cli=1&rich=1` or 560x900: | `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 +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` @@ -86,3 +88,22 @@ with `tool/capture` that those points still open the chats. 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. diff --git a/app/tool/perf/design_bench.mjs b/app/tool/perf/design_bench.mjs index a55ea7cf..870f8b97 100644 --- a/app/tool/perf/design_bench.mjs +++ b/app/tool/perf/design_bench.mjs @@ -6,7 +6,8 @@ // scenarios, records Flutter's FrameTiming (tool/perf/frame_log.dart) and // compares each design's medians with Default's. It exits 1 when a design // goes over budget: -// - build or raster sum of a scenario above `--ratio` x Default + `--slack` ms; +// - mean build or raster time per frame of a scenario above `--ratio` x +// Default + `--slack` ms; // - a request leaving the loopback origin (a font fallback fetch) that the // design makes and Default does not (Default's own are listed as baseline); // - live design switches growing the JS heap by more than `--leak` MB. @@ -29,7 +30,7 @@ const { values: opts } = parseArgs({ build: { type: 'string' }, out: { type: 'string' }, repeat: { type: 'string', default: '3' }, only: { type: 'string' }, designs: { type: 'string' }, gpu: { type: 'boolean' }, - ratio: { type: 'string', default: '1.35' }, slack: { type: 'string', default: '25' }, + ratio: { type: 'string', default: '1.35' }, slack: { type: 'string', default: '1' }, switches: { type: 'string', default: '10' }, leak: { type: 'string', default: '8' }, }, }); @@ -51,7 +52,7 @@ const SCENARIOS = [ ]; const median = (xs) => { const s = [...xs].sort((a, b) => a - b); return s[Math.floor(s.length / 2)] ?? 0; }; -const r1 = (x) => Math.round(x * 10) / 10; +const r1 = (x) => Math.round(x * 100) / 100; const server = await serveBuild(opts.build); const browser = await openBrowser({ gpu: Boolean(opts.gpu) }); @@ -153,7 +154,9 @@ async function measure(s, design, others) { const f = frames.slice(start).filter((x) => x[0] + x[1] > 300); const sum = (i) => f.reduce((a, x) => a + x[i], 0) / 1000; const max = (i) => f.reduce((a, x) => Math.max(a, x[i]), 0) / 1000; - return { ...out, frames: f.length, buildSum: sum(0), buildMax: max(0), rasterSum: sum(1), + const mean = (i) => (f.length ? sum(i) / f.length : 0); + return { ...out, frames: f.length, buildMean: mean(0), rasterMean: mean(1), + buildSum: sum(0), buildMax: max(0), rasterSum: sum(1), rasterMax: max(1), over16: f.filter((x) => x[2] > 16667).length }; } @@ -186,7 +189,9 @@ try { console.log(`${s.name.padEnd(7)} ${design.padEnd(10)} ${JSON.stringify(row)}`); const base = results[s.name].default; if (design !== 'default' && base) { - for (const key of ['buildSum', 'rasterSum']) { + // Per-frame means, not sums: a cheaper design draws more frames in + // the same gesture, so its sum can exceed a slower design's. + for (const key of ['buildMean', 'rasterMean']) { const limit = base[key] * Number(opts.ratio) + Number(opts.slack); if (row[key] > limit) failures.push(`${s.name}/${design}: ${key} ${row[key]} ms > ${r1(limit)} ms (Default ${base[key]})`); }