perf: build unshown run-detail tabs after the route transition; interaction bench
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.
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
// Attributes a V8 CPU profile of the fixture app to Dart source files through
|
||||
// the build's source map (`flutter build web --profile --source-maps`), for
|
||||
// tool/perf/interaction_bench.mjs --cpuprofile.
|
||||
//
|
||||
// Each sample's stack is mapped frame by frame (a JS function's start position
|
||||
// to its Dart file and line); a file or function counts once per sample, so
|
||||
// the numbers are inclusive milliseconds. Frames without a mapping (CanvasKit,
|
||||
// the browser) are grouped by their script.
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
const B64 = Object.fromEntries([...'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'].map((c, i) => [c, i]));
|
||||
|
||||
function decodeVlq(segment) {
|
||||
const out = [];
|
||||
let value = 0;
|
||||
let shift = 0;
|
||||
for (const c of segment) {
|
||||
const digit = B64[c];
|
||||
value += (digit & 31) << shift;
|
||||
if (digit & 32) { shift += 5; continue; }
|
||||
out.push(value & 1 ? -(value >>> 1) : value >>> 1);
|
||||
value = 0;
|
||||
shift = 0;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Loads `<dir>/main.dart.js.map`: lookup(line, column) -> { source, line } or null. */
|
||||
export async function loadSourceMap(dir) {
|
||||
const map = JSON.parse(await readFile(`${dir}/main.dart.js.map`, 'utf8'));
|
||||
const lines = [];
|
||||
let src = 0;
|
||||
let srcLine = 0;
|
||||
let srcCol = 0;
|
||||
let name = 0;
|
||||
map.mappings.split(';').forEach((line) => {
|
||||
const segments = [];
|
||||
let col = 0;
|
||||
for (const seg of line.split(',')) {
|
||||
if (!seg) continue;
|
||||
const v = decodeVlq(seg);
|
||||
col += v[0];
|
||||
if (v.length >= 4) {
|
||||
src += v[1]; srcLine += v[2]; srcCol += v[3];
|
||||
if (v.length >= 5) name += v[4];
|
||||
segments.push([col, src, srcLine, v.length >= 5 ? name : -1]);
|
||||
}
|
||||
}
|
||||
lines.push(segments);
|
||||
});
|
||||
return (line, column) => {
|
||||
const segs = lines[line];
|
||||
if (!segs?.length) return null;
|
||||
let lo = 0;
|
||||
let hi = segs.length - 1;
|
||||
let hit = null;
|
||||
while (lo <= hi) {
|
||||
const mid = (lo + hi) >> 1;
|
||||
if (segs[mid][0] <= column) { hit = segs[mid]; lo = mid + 1; } else hi = mid - 1;
|
||||
}
|
||||
hit ??= segs[0];
|
||||
const source = map.sources[hit[1]]
|
||||
.replace(/^.*\/packages\/flutter\/lib\/src\//, 'flutter/')
|
||||
.replace(/^.*\/pipelines_app\/lib\//, 'app:')
|
||||
.replace(/^(\.\.\/)+lib\//, 'app:')
|
||||
.replace(/^org-dartlang-sdk:\/\/\/(lib\/)?/, 'sdk:');
|
||||
return { source, line: hit[2] + 1, name: hit[3] >= 0 ? map.names[hit[3]] : null };
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Inclusive ms per Dart file and per Dart function (`file:line name`) across
|
||||
* the profile's samples; [filter] keeps the keys worth printing.
|
||||
*/
|
||||
export function attribute(profile, lookup, { n = 30, filter = () => true } = {}) {
|
||||
const byId = new Map(profile.nodes.map((node) => [node.id, node]));
|
||||
const parent = new Map();
|
||||
for (const node of profile.nodes) for (const c of node.children ?? []) parent.set(c, node.id);
|
||||
const where = new Map();
|
||||
for (const node of profile.nodes) {
|
||||
const f = node.callFrame;
|
||||
const mapped = f.url.endsWith('main.dart.js') ? lookup(f.lineNumber, f.columnNumber) : null;
|
||||
where.set(node.id, mapped
|
||||
? { file: mapped.source, fn: `${mapped.source}:${mapped.line} ${f.functionName}` }
|
||||
: { file: `(${f.url.split('/').pop() || f.functionName})`, fn: null });
|
||||
}
|
||||
const files = new Map();
|
||||
const fns = new Map();
|
||||
let busy = 0;
|
||||
profile.samples.forEach((id, i) => {
|
||||
const dt = (profile.timeDeltas[i + 1] ?? 0) / 1000;
|
||||
if (['(idle)', '(program)'].includes(byId.get(id).callFrame.functionName)) return;
|
||||
busy += dt;
|
||||
const seenFiles = new Set();
|
||||
const seenFns = new Set();
|
||||
for (let cur = id; cur !== undefined; cur = parent.get(cur)) {
|
||||
const w = where.get(cur);
|
||||
if (!seenFiles.has(w.file)) { seenFiles.add(w.file); files.set(w.file, (files.get(w.file) ?? 0) + dt); }
|
||||
if (w.fn && !seenFns.has(w.fn)) { seenFns.add(w.fn); fns.set(w.fn, (fns.get(w.fn) ?? 0) + dt); }
|
||||
}
|
||||
});
|
||||
const r1 = (x) => Math.round(x * 10) / 10;
|
||||
const top = (m) => [...m].filter(([k]) => filter(k)).sort((a, b) => b[1] - a[1]).slice(0, n).map(([k, v]) => `${r1(v)} ${k}`);
|
||||
return { busyMs: r1(busy), files: top(files), functions: top(fns) };
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Frame report for the interaction bench (tool/perf/interaction_bench.mjs).
|
||||
//
|
||||
// With `?perf=1` the full-app fixture prints every frame's Flutter timings to
|
||||
// the console as `PERF_FRAME <build us> <raster us> <total us>`, and the first
|
||||
// rasterised frame as `PERF_FIRST_FRAME <ms since navigation>`.
|
||||
// `window.__perfKick()` schedules a frame, so the engine hands over timings it
|
||||
// is still holding back (the web engine reports them in batches). Without the
|
||||
// flag nothing is installed.
|
||||
import 'dart:js_interop';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:web/web.dart' as web;
|
||||
|
||||
@JS('__perfKick')
|
||||
external set _perfKick(JSFunction kick);
|
||||
|
||||
void installFrameLog(Map<String, String> params) {
|
||||
if (params['perf'] != '1') return;
|
||||
final binding = WidgetsFlutterBinding.ensureInitialized();
|
||||
binding.addTimingsCallback((timings) {
|
||||
for (final timing in timings) {
|
||||
// ignore: avoid_print
|
||||
print(
|
||||
'PERF_FRAME ${timing.buildDuration.inMicroseconds} '
|
||||
'${timing.rasterDuration.inMicroseconds} '
|
||||
'${timing.totalSpan.inMicroseconds}',
|
||||
);
|
||||
}
|
||||
});
|
||||
binding.waitUntilFirstFrameRasterized.then((_) {
|
||||
// ignore: avoid_print
|
||||
print('PERF_FIRST_FRAME ${web.window.performance.now().round()}');
|
||||
});
|
||||
_perfKick = (() => binding.scheduleFrame()).toJS;
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
#!/usr/bin/env node
|
||||
// Interaction bench over the full-app fixture (tool/search_selection_probe_entry.dart,
|
||||
// built release). For each scenario it loads a route with `?perf=1`, runs the
|
||||
// setup steps, then records Flutter's FrameTiming (tool/perf/frame_log.dart)
|
||||
// for the measured steps until the page settles, and prints per-scenario
|
||||
// medians: frames, build sum / max, raster sum / max and the longest frame.
|
||||
// Startup reports the first rasterised frame (ms since navigation) and the
|
||||
// main.dart.js / canvaskit fetch times.
|
||||
//
|
||||
// --cpuprofile records a V8 CPU profile of the measured steps (first rep),
|
||||
// writes `<scenario>.cpuprofile` and prints the functions with the most
|
||||
// inclusive and self time; use a `flutter build web --profile` build so the
|
||||
// names are readable; add --source-maps to attribute time to Dart files
|
||||
// (tool/perf/cpu_attribution.mjs). --frames prints every measured frame's
|
||||
// build and raster time; --shots writes a screenshot after each scenario.
|
||||
//
|
||||
// node tool/perf/interaction_bench.mjs --build build/probe-app --out /tmp/bench \
|
||||
// [--repeat 5] [--only name,name] [--size 560x900] [--shots] [--cpuprofile] [--frames]
|
||||
//
|
||||
// Clicks are points (CSS px at 560x900, Material, light), so Flutter's
|
||||
// semantics tree stays off as for most users. Headless Chrome without a GPU:
|
||||
// CanvasKit rasterises on the CPU, so compare builds with each other rather
|
||||
// than predicting a device.
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { parseArgs } from 'node:util';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
import { openBrowser } from '../capture/browser.mjs';
|
||||
import { serveBuild } from '../capture/serve.mjs';
|
||||
import { attribute, loadSourceMap } from './cpu_attribution.mjs';
|
||||
|
||||
const { values: opts } = parseArgs({
|
||||
options: {
|
||||
build: { type: 'string' }, out: { type: 'string' }, repeat: { type: 'string', default: '5' },
|
||||
only: { type: 'string' }, cpuprofile: { type: 'boolean' }, frames: { type: 'boolean' }, shots: { type: 'boolean' }, size: { type: 'string', default: '560x900' },
|
||||
},
|
||||
});
|
||||
if (!opts.build || !opts.out) throw new Error('usage: --build <dir> --out <dir>');
|
||||
const [width, height] = opts.size.split('x').map(Number);
|
||||
|
||||
// Bottom tab bar and top-bar points at 560x900 (Material).
|
||||
const TAB = { first: [337, 854], second: [396, 854], third: [455, 854], fourth: [514, 854] };
|
||||
const TOP_RIGHT = [524, 32];
|
||||
const FIRST_ROW = [280, 138];
|
||||
|
||||
// `setup` runs unrecorded after load; `act` is recorded. A step is
|
||||
// `{ click: [x, y] }`, `{ type: 'text' }` (one character per 120 ms), `{ wait }`.
|
||||
const SCENARIOS = [
|
||||
{ name: 'startup', route: '/runs', act: [] },
|
||||
{ name: 'tab:runs->pipelines', route: '/runs', act: [{ click: TAB.first }] },
|
||||
{ name: 'tab:pipelines->runs', route: '/pipelines', act: [{ click: TAB.second }] },
|
||||
{ name: 'tab:runs->search', route: '/runs', act: [{ click: TAB.fourth }] },
|
||||
{ name: 'tab:runs->chat', route: '/runs', q: { chats: '30' }, act: [{ click: TAB.third }] },
|
||||
{ name: 'tab:runs->chat (150 chats)', route: '/runs', q: { chats: '150' }, act: [{ click: TAB.third }] },
|
||||
{ name: 'startup (150 chats)', route: '/runs', q: { chats: '150' }, act: [] },
|
||||
{ name: 'runs(400)->run detail', route: '/runs', q: { runs: '400' }, act: [{ click: FIRST_ROW }] },
|
||||
{ name: 'runs->run detail', route: '/runs', act: [{ click: FIRST_ROW }] },
|
||||
{ name: 'run tab:summary->timeline', route: '/runs/7', act: [{ click: TAB.second }] },
|
||||
{ name: 'run tab:timeline(400)', route: '/runs/7', q: { steps: '400' }, act: [{ click: TAB.second }] },
|
||||
{ name: 'run tab:->artifacts', route: '/runs/7', act: [{ click: TAB.third }] },
|
||||
{ name: 'run tab:->changes', route: '/runs/7', act: [{ click: TAB.fourth }] },
|
||||
{ name: 'timeline->visit page', route: '/runs/7', setup: [{ click: TAB.second }], act: [{ click: [280, 150] }] },
|
||||
{ name: 'run tab:timeline->summary', route: '/runs/7', setup: [{ click: TAB.second }], act: [{ click: TAB.first }] },
|
||||
{ name: 'run detail with graph preview', route: '/runs', q: { graph: '1' }, act: [{ click: FIRST_ROW }] },
|
||||
{ name: 'run graph full screen', route: '/runs/7', q: { graph: '1' }, act: [{ click: [512, 152] }] },
|
||||
{ name: 'artifact viewer open', route: '/runs/7', setup: [{ click: TAB.third }], act: [{ click: [280, 376] }] },
|
||||
{ name: 'search type "release" (200 hits)', route: '/search', q: { hits: '200' },
|
||||
setup: [{ click: [200, 32] }], act: [{ type: 'release' }] },
|
||||
{ name: 'pipelines->pipeline detail', route: '/pipelines', act: [{ click: [280, 155] }] },
|
||||
{ name: 'pipeline tab:->graph', route: '/pipelines/24', act: [{ click: TAB.third }] },
|
||||
{ name: 'pipeline tab:->source', route: '/pipelines/24', act: [{ click: TAB.fourth }] },
|
||||
{ name: 'chat list->open chat', route: '/chat', q: { chats: '30' }, act: [{ click: FIRST_ROW }] },
|
||||
{ name: 'pipelines->settings', route: '/pipelines', act: [{ click: TOP_RIGHT }] },
|
||||
];
|
||||
|
||||
const median = (xs) => { const s = [...xs].sort((a, b) => a - b); return s[Math.floor(s.length / 2)]; };
|
||||
const r1 = (x) => Math.round(x * 10) / 10;
|
||||
|
||||
const lookup = opts.cpuprofile ? await loadSourceMap(opts.build) : null;
|
||||
const server = await serveBuild(opts.build);
|
||||
const browser = await openBrowser();
|
||||
const { send, on } = browser;
|
||||
const evaluate = async (expression) => (await send('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true })).result?.value;
|
||||
let frames = [];
|
||||
let firstFrame = null;
|
||||
const errors = [];
|
||||
on('Runtime.consoleAPICalled', (p) => {
|
||||
const text = p.args.map((a) => a.value ?? '').join(' ');
|
||||
if (text.startsWith('PERF_FRAME ')) frames.push(text.split(' ').slice(1).map(Number));
|
||||
else if (text.startsWith('PERF_FIRST_FRAME ')) firstFrame = Number(text.split(' ')[1]);
|
||||
else if (p.type === 'error') errors.push(text.slice(0, 200));
|
||||
});
|
||||
on('Runtime.exceptionThrown', (p) => errors.push(String(p.exceptionDetails?.exception?.description ?? p.exceptionDetails?.text).slice(0, 200)));
|
||||
|
||||
async function tap([x, y]) {
|
||||
for (const type of ['mouseMoved', 'mousePressed', 'mouseReleased']) {
|
||||
await send('Input.dispatchMouseEvent', { type, x, y, button: 'left', clickCount: 1 });
|
||||
}
|
||||
}
|
||||
async function run(steps) {
|
||||
for (const step of steps ?? []) {
|
||||
if (step.click) { await tap(step.click); await delay(1200); }
|
||||
if (step.type) for (const ch of step.type) { await send('Input.insertText', { text: ch }); await delay(120); }
|
||||
if (step.wait) await delay(step.wait);
|
||||
}
|
||||
}
|
||||
// The engine hands timings over in batches; two late frames flush them.
|
||||
async function settle() {
|
||||
await delay(1500);
|
||||
for (let i = 0; i < 2; i++) { await evaluate('window.__perfKick?.()'); await delay(250); }
|
||||
}
|
||||
|
||||
await mkdir(opts.out, { recursive: true });
|
||||
const results = {};
|
||||
try {
|
||||
await send('Page.enable');
|
||||
await send('Runtime.enable');
|
||||
await send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: false });
|
||||
await send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: 'light' }] });
|
||||
const only = opts.only?.split(',');
|
||||
for (const s of SCENARIOS.filter((s) => !only || only.includes(s.name))) {
|
||||
const reps = [];
|
||||
for (let rep = 0; rep < Number(opts.repeat); rep++) {
|
||||
const url = new URL('/', server.origin);
|
||||
url.searchParams.set('route', s.route);
|
||||
url.searchParams.set('theme', 'light');
|
||||
url.searchParams.set('perf', '1');
|
||||
for (const [k, v] of Object.entries(s.q ?? {})) url.searchParams.set(k, v);
|
||||
frames = []; firstFrame = null;
|
||||
await send('Page.navigate', { url: url.href });
|
||||
for (let i = 0; i < 300 && firstFrame === null; i++) await delay(50);
|
||||
await delay(2000);
|
||||
const startup = s.name.startsWith('startup');
|
||||
const loads = startup ? await evaluate(`Object.fromEntries(performance.getEntriesByType('resource')
|
||||
.filter((e) => /main\\.dart\\.js|canvaskit\\.wasm/.test(e.name))
|
||||
.map((e) => [e.name.split('/').pop(), Math.round(e.responseEnd)]))`) : null;
|
||||
await run(s.setup);
|
||||
await settle();
|
||||
const startFrames = startup ? 0 : frames.length;
|
||||
const profiling = opts.cpuprofile && rep === 0;
|
||||
if (profiling) {
|
||||
await send('Profiler.enable');
|
||||
await send('Profiler.setSamplingInterval', { interval: 100 });
|
||||
await send('Profiler.start');
|
||||
}
|
||||
await run(s.act);
|
||||
await settle();
|
||||
if (profiling) {
|
||||
const { profile } = await send('Profiler.stop');
|
||||
await writeFile(join(opts.out, `${s.name.replace(/[^\w-]+/g, '_')}.cpuprofile`), JSON.stringify(profile));
|
||||
console.log(s.name, attribute(profile, lookup, { filter: (k) => k.startsWith('app:') || !k.includes(' ') }));
|
||||
}
|
||||
if (opts.shots && rep === 0) {
|
||||
const png = (await send('Page.captureScreenshot', { format: 'png' })).data;
|
||||
await writeFile(join(opts.out, `${s.name.replace(/[^\w-]+/g, '_')}.png`), Buffer.from(png, 'base64'));
|
||||
}
|
||||
const f = frames.slice(startFrames).filter((x) => x[0] + x[1] > 300);
|
||||
if (opts.frames) console.log(` ${s.name} rep ${rep} build/raster ms:`, f.map((x) => `${r1(x[0] / 1000)}/${r1(x[1] / 1000)}`).join(' '));
|
||||
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;
|
||||
reps.push({ frames: f.length, buildSum: sum(0), buildMax: max(0), rasterSum: sum(1), rasterMax: max(1),
|
||||
longest: max(2), over16: f.filter((x) => x[2] > 16667).length, firstFrame, ...loads });
|
||||
}
|
||||
const keys = Object.keys(reps[0]).filter((k) => typeof reps[0][k] === 'number');
|
||||
results[s.name] = Object.fromEntries(keys.map((k) => [k, r1(median(reps.map((r) => r[k])))]));
|
||||
results[s.name].reps = reps.length;
|
||||
console.log(s.name.padEnd(36), JSON.stringify(results[s.name]));
|
||||
}
|
||||
if (errors.length) console.log('page errors (first 5):', [...new Set(errors)].slice(0, 5));
|
||||
await writeFile(join(opts.out, 'interaction-bench.json'), JSON.stringify({ build: opts.build, size: opts.size, results }, null, 2));
|
||||
} finally {
|
||||
await browser.close().catch(() => {});
|
||||
await server.close();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env node
|
||||
// Splits main.dart.js by Dart source through its source map, to find deferred
|
||||
// loading candidates:
|
||||
//
|
||||
// flutter build web --release --source-maps --output build/size
|
||||
// node tool/perf/js_size_by_source.mjs build/size [depth=3]
|
||||
//
|
||||
// Every generated character is charged to the source of the mapping segment
|
||||
// it falls in (characters before a line's first segment, or in an unmapped
|
||||
// segment, count as "(unmapped)"). App sources are grouped to [depth] path
|
||||
// parts under lib/ (`features/chat/ui` at 3), other sources by package.
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
const [dir, depthArg = '3'] = process.argv.slice(2);
|
||||
if (!dir) throw new Error('usage: js_size_by_source.mjs <build dir> [depth]');
|
||||
const depth = Number(depthArg);
|
||||
const js = (await readFile(`${dir}/main.dart.js`, 'utf8')).split('\n');
|
||||
const map = JSON.parse(await readFile(`${dir}/main.dart.js.map`, 'utf8'));
|
||||
|
||||
const B64 = Object.fromEntries([...'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'].map((c, i) => [c, i]));
|
||||
function decode(segment) {
|
||||
const out = [];
|
||||
let value = 0;
|
||||
let shift = 0;
|
||||
for (const c of segment) {
|
||||
const digit = B64[c];
|
||||
value += (digit & 31) << shift;
|
||||
if (digit & 32) { shift += 5; continue; }
|
||||
out.push(value & 1 ? -(value >>> 1) : value >>> 1);
|
||||
value = 0;
|
||||
shift = 0;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function group(source) {
|
||||
const app = source.match(/(?:^|\/)lib\/((?:features|ui|shell|core|application)\/.*)$/);
|
||||
if (app && !source.includes('/packages/')) return `app:${app[1].split('/').slice(0, depth).join('/').replace(/\.dart$/, '')}`;
|
||||
const flutter = source.match(/packages\/flutter\/lib\/src\/(\w+)/);
|
||||
if (flutter) return `flutter/${flutter[1]}`;
|
||||
const pkg = source.match(/(?:pub\.dev|hosted\/[^/]+)\/([\w]+)-[\d.]+/) ?? source.match(/packages\/(\w+)\//);
|
||||
if (pkg) return `pkg:${pkg[1]}`;
|
||||
if (source.startsWith('org-dartlang-sdk')) return source.includes('_engine') ? 'sdk:web_engine' : 'sdk:dart';
|
||||
return source.split('/').slice(-2).join('/');
|
||||
}
|
||||
|
||||
const sizes = new Map();
|
||||
const add = (key, n) => sizes.set(key, (sizes.get(key) ?? 0) + n);
|
||||
let src = 0;
|
||||
map.mappings.split(';').forEach((line, i) => {
|
||||
const text = js[i] ?? '';
|
||||
let col = 0;
|
||||
let last = { col: 0, key: '(unmapped)' };
|
||||
for (const seg of line.split(',')) {
|
||||
if (!seg) continue;
|
||||
const v = decode(seg);
|
||||
col += v[0];
|
||||
add(last.key, col - last.col);
|
||||
if (v.length >= 4) src += v[1];
|
||||
last = { col, key: v.length >= 4 ? group(map.sources[src]) : '(unmapped)' };
|
||||
}
|
||||
add(last.key, text.length + 1 - last.col);
|
||||
});
|
||||
const total = js.reduce((n, l) => n + l.length + 1, 0);
|
||||
console.log(`main.dart.js ${(total / 1024).toFixed(0)} KiB`);
|
||||
for (const [k, v] of [...sizes].sort((a, b) => b[1] - a[1]).slice(0, 45)) {
|
||||
console.log(`${(v / 1024).toFixed(1).padStart(8)} KiB ${(100 * v / total).toFixed(1).padStart(5)}% ${k}`);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// Extra fixture data for the interaction bench (tool/perf/interaction_bench.mjs)
|
||||
// over the full-app probe (tool/search_selection_probe_entry.dart). Every
|
||||
// option defaults to off, so other captures see the fixture unchanged.
|
||||
//
|
||||
// `?hits=N` N more `release` run hits in Search;
|
||||
// `?chats=N` N chat sessions in the chat list, each opening a short
|
||||
// markdown transcript;
|
||||
// `?graph=1` run 7 carries its pinned graph (plan -> build).
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
Map<String, String> _params = const {};
|
||||
|
||||
/// Reads the options from the page URL's query, before the app rewrites it.
|
||||
void configurePerfFixture(Map<String, String> params) => _params = params;
|
||||
int get _hits => int.tryParse(_params['hits'] ?? '') ?? 0;
|
||||
int get _chats => int.tryParse(_params['chats'] ?? '') ?? 0;
|
||||
bool get perfRunGraph => _params['graph'] == '1';
|
||||
|
||||
/// Run 7's pinned graph for `?graph=1`.
|
||||
JsonMap perfRunGraphFixture() => {
|
||||
'name': 'Release train',
|
||||
'stages': [
|
||||
{
|
||||
'key': 'plan',
|
||||
'type': 'model',
|
||||
'edges': {'success': 'build', 'error': '#'},
|
||||
},
|
||||
{
|
||||
'key': 'build',
|
||||
'type': 'model',
|
||||
'edges': {'success': 'plan', 'error': '#failure'},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/// Filler run hits for a query that `release` text matches.
|
||||
List<JsonMap> perfSearchHits(String query, String kind) {
|
||||
if (_hits == 0 || (kind.isNotEmpty && kind != 'run')) return const [];
|
||||
if (query.isNotEmpty && !'release filler run'.contains(query)) {
|
||||
return const [];
|
||||
}
|
||||
return [
|
||||
for (var i = 0; i < _hits; i++)
|
||||
{
|
||||
'kind': 'run',
|
||||
'target': 'run:${1000 + i}',
|
||||
'score': 1,
|
||||
'recency': '2026-10-18T08:42:00Z',
|
||||
'run': {
|
||||
'id': 1000 + i,
|
||||
'pipeline_name': 'Release filler $i',
|
||||
'status': i % 3 == 0 ? 'failed' : 'succeeded',
|
||||
'workspace': '/srv/probe/release',
|
||||
'created_at': '2026-10-18T08:12:00Z',
|
||||
'finished_at': '2026-10-18T08:42:00Z',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
String _answer(int i) =>
|
||||
'## Answer $i\n\nSome **bold** text with `code`.\n\n'
|
||||
'```dart\n${List.generate(8, (l) => 'final v$l = $i * $l;').join('\n')}'
|
||||
'\n```\n\n- one\n- two\n';
|
||||
|
||||
/// Chat replies for `?chats=N`, or null to fall through to the fixture.
|
||||
JsonMap? perfChatReply(JsonMap request) {
|
||||
if (_chats == 0) return null;
|
||||
final id = request['id'];
|
||||
switch ('${request['type']}') {
|
||||
case 'chat_sessions':
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_sessions',
|
||||
'chat_sessions': [
|
||||
for (var i = 0; i < _chats; i++)
|
||||
{
|
||||
'id': 'perf-chat-$i',
|
||||
'title': 'Fixture chat ${i + 1}',
|
||||
'directory': '/workspace/demo',
|
||||
},
|
||||
],
|
||||
};
|
||||
case 'chat_subscribe':
|
||||
return {'id': id, 'type': 'chat_subscribed'};
|
||||
case 'chat_shells':
|
||||
return {'id': id, 'type': 'chat_shells', 'chat_shells': const []};
|
||||
case 'chat_messages':
|
||||
return {
|
||||
'id': id,
|
||||
'type': 'chat_messages',
|
||||
'chat_history': {
|
||||
'messages': [
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
'id': 'perf-m$i',
|
||||
'role': i.isEven ? 'user' : 'assistant',
|
||||
'parts': [
|
||||
{
|
||||
'type': 'text',
|
||||
'text': i.isEven ? 'Question $i' : _answer(i),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'next_cursor': '',
|
||||
'has_more': false,
|
||||
},
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -28,6 +28,8 @@ import 'package:web/web.dart' as web;
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
|
||||
import 'perf/backdrop_census.dart';
|
||||
import 'perf/frame_log.dart';
|
||||
import 'perf/perf_fixture.dart';
|
||||
import 'probe_folder_fixture.dart';
|
||||
|
||||
/// The run every run-scoped hit names. Its recorded sequences are deliberately
|
||||
@@ -82,6 +84,7 @@ JsonMap probeRunDetail() => {
|
||||
},
|
||||
..._fillerSteps(),
|
||||
],
|
||||
if (perfRunGraph) 'graph': perfRunGraphFixture(),
|
||||
};
|
||||
|
||||
/// Extra rows for scroll-performance captures (`?runs=N`, `?steps=N`). Both
|
||||
@@ -366,6 +369,8 @@ JsonMap? probeReply(JsonMap request) {
|
||||
'type': 'error',
|
||||
'error': message,
|
||||
};
|
||||
final perf = perfChatReply(request);
|
||||
if (perf != null) return perf;
|
||||
switch (type) {
|
||||
case 'subscribe':
|
||||
case 'unsubscribe':
|
||||
@@ -416,6 +421,7 @@ JsonMap? probeReply(JsonMap request) {
|
||||
if ((kind.isEmpty || entry.hit['kind'] == kind) &&
|
||||
(query.isEmpty || entry.haystack.toLowerCase().contains(query)))
|
||||
entry.hit,
|
||||
...perfSearchHits(query, kind),
|
||||
];
|
||||
return {
|
||||
'id': id,
|
||||
@@ -520,6 +526,9 @@ class _FixtureSink implements WebSocketSink {
|
||||
/// `?q=release` types that query into Search once its field is shown;
|
||||
/// `?platform=cupertino` renders the Cupertino host (`material`, the
|
||||
/// default, renders Material as browsers do);
|
||||
/// `?perf=1` prints frame timings (tool/perf/frame_log.dart);
|
||||
/// `?hits=N`, `?chats=N` and `?graph=1` add bench data
|
||||
/// (tool/perf/perf_fixture.dart);
|
||||
/// `?theme=dark` / `?theme=light` pins the platform brightness the app's
|
||||
/// `ThemeMode.system` follows (omitted: the browser's color scheme).
|
||||
///
|
||||
@@ -527,6 +536,8 @@ class _FixtureSink implements WebSocketSink {
|
||||
void main() {
|
||||
final params = Uri.base.queryParameters;
|
||||
installBackdropCensus();
|
||||
installFrameLog(params);
|
||||
configurePerfFixture(params);
|
||||
_fillerRunCount = int.tryParse(params['runs'] ?? '') ?? 0;
|
||||
_fillerStepCount = int.tryParse(params['steps'] ?? '') ?? 0;
|
||||
final cupertino = params['platform'] == 'cupertino';
|
||||
|
||||
Reference in New Issue
Block a user