| 1 | // The feed's measurement layer (dev tooling, `?feed=1` → the **bench** button / |
| 2 | // `?bench=1`; the web twin of the iOS feed-report.json, docs/chat-feed-ios.md). |
| 3 | // It runs the same feed — corpus/common, the same bubble count, the same |
| 4 | // scripted `step` scroll — N passes per renderer × pool setting and records |
| 5 | // what happened: every boot (feed.ts's `BootRecord`: creation → content, |
| 6 | // visible-without-content time, renderer creation → ready, host constructor |
| 7 | // time), the main thread during the scroll (PerformanceObserver long tasks and |
| 8 | // a requestAnimationFrame loop for frame intervals), and memory samples |
| 9 | // (`performance.memory` every second; `measureUserAgentSpecificMemory` at the |
| 10 | // baseline and the end of each pass where the browser exposes it). Nothing is |
| 11 | // typed in: the two tables, the overlay text and the JSON report are rendered |
| 12 | // from the same `FeedReport` object, median / p90 in every cell. |
| 13 | // |
| 14 | // Method (what makes the numbers comparable): |
| 15 | // - one browser tab, one feed, every combination in the same session, back to back; |
| 16 | // - a pass = fresh pool (prewarmed before the feed opens, like a messenger at |
| 17 | // launch) → `reset` → the first screen settles → the scripted scroll down |
| 18 | // and back → stragglers settle → the pass is read out; |
| 19 | // - cold = the first boot of a pass; warm = every other boot of the pass; |
| 20 | // - per-bubble rows: median / p90 over the pass's bubbles, then the median of |
| 21 | // those over the N passes; per-pass rows: median / p90 over the N passes; |
| 22 | // - the demo's own periodic work (overlay refresh, memory and canary polls) |
| 23 | // is paused while a pass runs. |
| 24 | // Trusted glue only; nothing here touches the sandbox, the validator or a renderer. |
| 25 | |
| 26 | import type { BootRecord, FeedApi, FeedCorpus, FeedRenderer } from './feed'; |
| 27 | |
| 28 | export interface MemorySample { |
| 29 | /** performance.now() */ |
| 30 | t: number; |
| 31 | /** Bytes, or null when no source is available. */ |
| 32 | total: number | null; |
| 33 | workers: number | null; |
| 34 | frames: number | null; |
| 35 | source: 'measureUserAgentSpecificMemory' | 'performance.memory' | 'performance.memory+gc' | 'none'; |
| 36 | /** Why the precise API was not used (its error), when it exists but refuses. */ |
| 37 | note?: string; |
| 38 | /** Resident memory of every browser process (bytes), read by the Playwright driver through `__twProcessMemory`; null in a plain tab. */ |
| 39 | process: number | null; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Reads what the browser offers: the precise API (workers and frames in the |
| 44 | * breakdown) or the page's JS heap. `gc` runs `window.gc()` first where it is |
| 45 | * exposed (`--js-flags=--expose-gc`, the Playwright driver): performance.memory |
| 46 | * counts garbage otherwise. |
| 47 | */ |
| 48 | export async function measureMemory(opts: { precise?: boolean; timeoutMs?: number; gc?: boolean } = {}): Promise |
| 49 | const p = performance as any; |
| 50 | const t = performance.now(); |
| 51 | const gc = (globalThis as any).gc; |
| 52 | if (opts.gc && typeof gc === 'function') gc(); |
| 53 | // scripts/feed-report.ts exposes it: the RSS of every Chromium process (workers, frames, GPU, the lot), the number a device feels. |
| 54 | const procFn = (globalThis as any).__twProcessMemory; |
| 55 | const process: number | null = typeof procFn === 'function' ? await procFn().catch(() => null |
| 56 | let note: string | undefined; |
| 57 | if (opts.precise !== false && typeof p.measureUserAgentSpecificMemory === 'function') { |
| 58 | try { |
| 59 | // The page is cross-origin isolated (Vite sends COOP/COEP): workers and the srcdoc frames are in the breakdown. |
| 60 | // The browser delays the answer by a random interval; the caller bounds the wait. |
| 61 | const r = await Promise.race([ |
| 62 | p.measureUserAgentSpecificMemory() as Promise<{ bytes: number; breakdown: { bytes: number; attribution: { scope?: string; container?: |
| 63 | new Promise<null>((res) => setTimeout(() => res(null), opts.timeoutMs ?? 20_000)), |
| 64 | ]); |
| 65 | if (r) { |
| 66 | let workers = 0, frames = 0; |
| 67 | for (const e of r.breakdown) { |
| 68 | if (e.attribution.some((a) => a.scope?.includes('Worker'))) workers += e.bytes; |
| 69 | else if (e.attribution.some((a) => a.container)) frames += e.bytes; |
| 70 | } |
| 71 | return { t, total: r.bytes, workers, frames, source: 'measureUserAgentSpecificMemory', process }; |
| 72 | } |
| 73 | note = 'measureUserAgentSpecificMemory: no answer within the wait'; |
| 74 | } catch (e) { note = 'measureUserAgentSpecificMemory: ' + String(e).split('\n')[0]; } |
| 75 | } |
| 76 | if (p.memory) return { t, total: p.memory.usedJSHeapSize as number, workers: null, frames: null, source: opts.gc && typeof gc === 'function' ? 'performance.memory+gc' : 'performance.memory', note, process }; |
| 77 | return { t, total: null, workers: null, frames: null, source: 'none', note, process }; |
| 78 | } |
| 79 | |
| 80 | export interface Combo { renderer: FeedRenderer; pool: boolean } |
| 81 | export interface BenchOptions { |
| 82 | passes: number; |
| 83 | count: number; |
| 84 | corpus: FeedCorpus; |
| 85 | combos: Combo[]; |
| 86 | /** Fill the pool before the feed opens (a messenger prewarms at launch); off = the pool fills while the first screen boots. */ |
| 87 | prewarm: boolean; |
| 88 | /** Seconds the first screen gets before the scroll starts, and the settle time after it. */ |
| 89 | settleMs: number; |
| 90 | } |
| 91 | |
| 92 | export interface PassResult { |
| 93 | pass: number; |
| 94 | seconds: number; |
| 95 | records: BootRecord[]; |
| 96 | /** Boots that got no content in this pass and were not killed (scrolled past, dropped while booting). */ |
| 97 | incomplete: number; |
| 98 | longTasks: { count: number; totalMs: number; maxMs: number; scrollSeconds: number }; |
| 99 | /** Milliseconds the document was hidden during the scroll (a background tab: frames and timers throttled, the pass is not comparable). */ |
| 100 | hiddenMs: number; |
| 101 | frames: { count: number; expectedMs: number; dropped: number; maxMs: number; p95Ms: number; over32: |
| 102 | memory: { |
| 103 | baseline: MemorySample; |
| 104 | end: MemorySample; |
| 105 | liveAtEnd: number; |
| 106 | /** |
| 107 | * The ramp: after the scroll, the drop distance is lifted and the feed is scrolled through once more so every bubble |
| 108 | * boots and stays live; `pre` is read before it (the keep window live), `all` with every bubble live. Per bubble = |
| 109 | * (all − pre) ÷ (liveAll − livePre): a large signal against the browser's drift. `heapsAll` = Σ live QuickJS heaps then. |
| 110 | */ |
| 111 | ramp: { pre: MemorySample; all: MemorySample; livePre: number; liveAll: number; heapsAll: number; seconds: |
| 112 | /** Once a second while the pass runs: `performance.memory`, the browser's process memory (driver only), the live host count and the sum of the live QuickJS heaps. */ |
| 113 | samples: { t: number; total: number | null; process: number | null; live: number |
| 114 | }; |
| 115 | pool: { size: number; created: number; hits: number; misses: number } | null; |
| 116 | } |
| 117 | |
| 118 | /** A cell: median / p90, how many samples, and the unit. `null` = not measured in this run. */ |
| 119 | export interface Cell { median: number; p90: number; n: number } |
| 120 | |
| 121 | export interface ComboResult extends Combo { |
| 122 | key: string; |
| 123 | passes: PassResult[]; |
| 124 | cells: Record<string, Cell | null>; |
| 125 | notes: string[]; |
| 126 | } |
| 127 | |
| 128 | export interface FeedReport { |
| 129 | kind: 'twidget-feed-report-web'; |
| 130 | date: string; |
| 131 | userAgent: string; |
| 132 | platform: { cores: number; dpr: number; window: { width: number; height: number }; scroller: { width |
| 133 | config: { |
| 134 | corpus: FeedCorpus; count: number; passes: number; prewarm: boolean; settleMs: number; |
| 135 | scroll: { kind: 'step'; screenFraction: number; pauseMs: number }; |
| 136 | lanes: number; ahead: number; keep: number; poolSize: number; hostile: string; |
| 137 | }; |
| 138 | rows: RowDef[]; |
| 139 | combos: ComboResult[]; |
| 140 | notMeasured: string[]; |
| 141 | /** Set when the run was interrupted. */ |
| 142 | aborted?: string; |
| 143 | totalSeconds: number; |
| 144 | } |
| 145 | |
| 146 | /** What one table row is: which claim it belongs to, how it is read from a pass, how it is shown. */ |
| 147 | export interface RowDef { |
| 148 | key: string; |
| 149 | group: 'start' | 'scale' | 'native'; |
| 150 | label: string; |
| 151 | unit: 'ms' | 'MB' | 'n' | 'ms/s'; |
| 152 | /** 'bubble': per-bubble values within a pass (median / p90 over bubbles, the median of those across passes); 'pass': one value per pass (median / p90 across passes). */ |
| 153 | kind: 'bubble' | 'pass'; |
| 154 | title: string; |
| 155 | } |
| 156 | |
| 157 | export const GROUPS: Record<RowDef['group'], { label: string; claim: string }> = { |
| 158 | start: { label: 'starts instantly', claim: 'the pool: a bubble shows content as it scrolls in, not after its QuickJS boots' }, |
| 159 | scale: { label: 'cheap at scale', claim: 'the renderer: what one more live bubble costs the page' }, |
| 160 | native: { label: 'feels native under the finger', claim: 'the main thread during the scripted scroll' }, |
| 161 | }; |
| 162 | |
| 163 | export const ROWS: RowDef[] = [ |
| 164 | { key: 'ttfpCold', group: 'start', label: 'time to first content, cold (first bubble of a pass)', unit: 'ms', kind: 'pass', title: 'host creation → the first size report with content, for the first boot of each pass (one sample per pass: median / p90 across passes)' }, |
| 165 | { key: 'ttfpWarm', group: 'start', label: 'time to first content, warm', unit: 'ms', kind: 'bubble', title: 'host creation → first content for every boot after the first one of the pass' }, |
| 166 | { key: 'blank', group: 'start', label: 'blank while visible', unit: 'ms', kind: 'bubble', title: 'how long a bubble sat inside the viewport without content, per boot (0 = content was there before the reader got to it); boots that never got content count their whole visible time' }, |
| 167 | { key: 'blankCount', group: 'start', label: 'bubbles blank > 100 ms', unit: 'n', kind: 'pass', title: 'boots whose visible-without-content time exceeded 100 ms, per pass' }, |
| 168 | { key: 'rendererReady', group: 'start', label: 'renderer create → first report', unit: 'ms', kind: 'bubble', title: 'the renderer alone: its construction → its first message to the host (iframe: the srcdoc document load + renderer bundle, then the first size report; shadow: the first size report, synchronous; canvas: `ready` after the wasm instance, cached after the first)' }, |
| 169 | { key: 'hostCreate', group: 'start', label: 'host constructor (main thread)', unit: 'ms', kind: 'bubble', title: 'the synchronous cost of `new WidgetHost` on the main thread: renderer element, validator, worker handoff' }, |
| 170 | { key: 'memProcess', group: 'scale', label: 'memory per live bubble, browser processes', unit: 'MB', kind: 'pass', title: 'the memory ramp at the end of each pass: the drop distance is lifted and the feed is scrolled through once more so every bubble boots and stays live; (resident memory of every Chromium process with all bubbles live − with the keep window live) ÷ the bubbles added. Read by the Playwright driver (scripts/feed-report.ts); n/a in a plain tab' }, |
| 171 | { key: 'memPage', group: 'scale', label: 'memory per live bubble, page JS heap', unit: 'MB', kind: 'pass', title: 'the same ramp on performance.memory (the main thread\'s V8 heap: not the workers, not an isolated frame\'s heap), after gc() where the browser exposes it; n/a without performance.memory' }, |
| 172 | { key: 'qjsPerBubble', group: 'scale', label: 'QuickJS heap per live bubble', unit: 'MB', kind: 'pass', title: 'the engine\'s own counter (memory_used_size) summed over the live widgets ÷ live widgets, at the ramp\'s reading with every bubble live' }, |
| 173 | { key: 'rampLive', group: 'scale', label: 'live bubbles at the memory reading', unit: 'n', kind: 'pass', title: 'hosts alive at the ramp\'s reading (every bubble of the feed when the ramp completed)' }, |
| 174 | { key: 'longTotal', group: 'native', label: 'long tasks, total', unit: 'ms', kind: 'pass', title: 'PerformanceObserver longtask (≥ 50 ms) on the main thread during the scripted scroll, summed per pass' }, |
| 175 | { key: 'longRate', group: 'native', label: 'long-task time per second of scroll', unit: 'ms/s', kind: 'pass', title: 'the total above ÷ the seconds the scripted scroll took (comparable to the iOS hitch rate in spirit, not in definition)' }, |
| 176 | { key: 'longMax', group: 'native', label: 'longest task', unit: 'ms', kind: 'pass', title: 'the longest single long task during the scroll' }, |
| 177 | { key: 'frameMax', group: 'native', label: 'longest frame', unit: 'ms', kind: 'pass', title: 'the longest interval between two requestAnimationFrame callbacks during the scroll' }, |
| 178 | { key: 'dropped', group: 'native', label: 'dropped frames (estimate)', unit: 'n', kind: 'pass', title: 'Σ round(interval ÷ expected) − 1 over the frames of the scroll; expected = the 20th-percentile interval of the pass (the display\'s refresh)' }, |
| 179 | ]; |
| 180 | |
| 181 | export const NOT_MEASURED = [ |
| 182 | 'memory: performance.memory is the main thread\'s JS heap only (no workers, no isolated frame); measureUserAgentSpecificMemory is refused by this Chromium (the note under the table says so when it is); the process row is resident memory (shared pages counted once per process) over a ramp of ~1 minute: the browser\'s own drift over that minute is in it, the pool\'s warm workers are not', |
| 183 | 'the pool\'s prewarm itself (N worker boots before the feed opens) is outside every clock', |
| 184 | 'cold cache: wasm modules and the dev server\'s files are fetched once per page load, so only the first pass of a canvas renderer pays the fetch + compile', |
| 185 | 'a background tab: Chromium throttles timers and frames there; run with the tab in front', |
| 186 | 'CPU frequency, thermal state, other tabs and processes; the dev build (Vite, unminified)', |
| 187 | 'the iOS report\'s hitch rate: long tasks start at 50 ms, so shorter main-thread stalls show only in the frame rows', |
| 188 | ]; |
| 189 | |
| 190 | const quantile = (xs: number[], q: number) => { |
| 191 | if (!xs.length) return NaN; |
| 192 | const s = [...xs].sort((a, b) => a - b); |
| 193 | return s[Math.min(s.length - 1, Math.floor(s.length * q))]; |
| 194 | }; |
| 195 | const median = (xs: number[]) => quantile(xs, 0.5); |
| 196 | const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms)); |
| 197 | const MB = 1048576; |
| 198 | |
| 199 | // ───────────── one pass → cell values ───────────── |
| 200 | |
| 201 | /** Per-bubble values of a pass for a 'bubble' row; one value for a 'pass' row (NaN = not available in this pass). */ |
| 202 | function passValues(row: RowDef, p: PassResult): number[] | number { |
| 203 | const ok = p.records.filter((r) => r.contentMs !== null && !r.dead); |
| 204 | switch (row.key) { |
| 205 | case 'ttfpCold': { const c = ok.find((r) => r.cold); return c ? c.contentMs! : NaN; } |
| 206 | case 'ttfpWarm': return ok.filter((r) => !r.cold).map((r) => r.contentMs!); |
| 207 | case 'blank': return p.records.filter((r) => r.shownAt && !r.dead).map((r) => r.blankMs); |
| 208 | case 'blankCount': return p.records.filter((r) => r.shownAt && !r.dead && r.blankMs > 100).length; |
| 209 | case 'rendererReady': return p.records.filter((r) => r.rendererReadyMs !== null).map((r) => r.rendererReadyMs!); |
| 210 | case 'hostCreate': return p.records.map((r) => r.hostCreateMs); |
| 211 | case 'memProcess': { |
| 212 | const r = p.memory.ramp; |
| 213 | if (!r || r.pre.process === null || r.all.process === null || r.liveAll - r.livePre < 5) return NaN; |
| 214 | return (r.all.process - r.pre.process) / (r.liveAll - r.livePre) / MB; |
| 215 | } |
| 216 | case 'memPage': { |
| 217 | const r = p.memory.ramp; |
| 218 | if (!r || r.pre.total === null || r.all.total === null || r.pre.source !== r.all.source || r.liveAll - r.livePre < 5) return |
| 219 | return (r.all.total - r.pre.total) / (r.liveAll - r.livePre) / MB; |
| 220 | } |
| 221 | case 'qjsPerBubble': { |
| 222 | const r = p.memory.ramp; |
| 223 | return r && r.liveAll > 0 && r.heapsAll > 0 ? r.heapsAll / r.liveAll / MB : NaN; |
| 224 | } |
| 225 | case 'rampLive': return p.memory.ramp ? p.memory.ramp.liveAll : NaN; |
| 226 | case 'longTotal': return p.longTasks.totalMs; |
| 227 | case 'longRate': return p.longTasks.scrollSeconds > 0 ? p.longTasks.totalMs / p.longTasks.scrollSeconds : NaN; |
| 228 | case 'longMax': return p.longTasks.count ? p.longTasks.maxMs : 0; |
| 229 | case 'frameMax': return p.frames.count ? p.frames.maxMs : NaN; |
| 230 | case 'dropped': return p.frames.count ? p.frames.dropped : NaN; |
| 231 | } |
| 232 | return NaN; |
| 233 | } |
| 234 | |
| 235 | /** The cell for a row over a combination's passes (null when no pass had the value). */ |
| 236 | export function cell(row: RowDef, passes: PassResult[]): Cell | null { |
| 237 | if (row.kind === 'bubble') { |
| 238 | const meds: number[] = [], p90s: number[] = []; |
| 239 | let n = 0; |
| 240 | for (const p of passes) { |
| 241 | const xs = passValues(row, p) as number[]; |
| 242 | if (!xs.length) continue; |
| 243 | meds.push(median(xs)); p90s.push(quantile(xs, 0.9)); n += xs.length; |
| 244 | } |
| 245 | return meds.length ? { median: median(meds), p90: median(p90s), n } : null; |
| 246 | } |
| 247 | const xs = passes.map((p) => passValues(row, p) as number).filter((v) => Number.isFinite(v)); |
| 248 | return xs.length ? { median: median(xs), p90: quantile(xs, 0.9), n: xs.length } : null; |
| 249 | } |
| 250 | |
| 251 | export function formatValue(v: number, unit: RowDef['unit']): string { |
| 252 | if (!Number.isFinite(v)) return 'n/a'; |
| 253 | switch (unit) { |
| 254 | case 'ms': return Math.abs(v) < 10 && v !== 0 ? v.toFixed(1) : v.toFixed(0); |
| 255 | case 'ms/s': return v.toFixed(1); |
| 256 | case 'MB': return v.toFixed(1); |
| 257 | case 'n': return v.toFixed(0); |
| 258 | } |
| 259 | } |
| 260 | export function formatCell(c: Cell | null, unit: RowDef['unit']): string { |
| 261 | if (!c) return 'n/a'; |
| 262 | const u = unit === 'n' ? '' : ` ${unit}`; |
| 263 | return `${formatValue(c.median, unit)} / ${formatValue(c.p90, unit)}${u}`; |
| 264 | } |
| 265 | |
| 266 | // ───────────── tables (DOM and Markdown from the same report) ───────────── |
| 267 | |
| 268 | export interface TableSpec { title: string; columns: { label: string; combo: ComboResult }[] } |
| 269 | |
| 270 | /** The two tables: (1) every renderer with the pool on; (2) pool off vs on for each renderer that ran both. */ |
| 271 | export function tables(report: FeedReport): TableSpec[] { |
| 272 | const out: TableSpec[] = []; |
| 273 | const poolOn = report.combos.filter((c) => c.pool); |
| 274 | if (poolOn.length) out.push({ title: 'Renderers, pool on', columns: poolOn.map((c) => ({ label: c.renderer, combo: c })) }); |
| 275 | const both: TableSpec['columns'] = []; |
| 276 | for (const r of [...new Set(report.combos.map((c) => c.renderer))]) { |
| 277 | const off = report.combos.find((c) => c.renderer === r && !c.pool); |
| 278 | const on = report.combos.find((c) => c.renderer === r && c.pool); |
| 279 | if (off && on) both.push({ label: `${r}, pool off`, combo: off }, { label: `${r}, pool on`, combo: on }); |
| 280 | } |
| 281 | if (both.length) out.push({ title: 'Pool off vs on', columns: both }); |
| 282 | return out; |
| 283 | } |
| 284 | |
| 285 | export function toMarkdown(report: FeedReport): string { |
| 286 | const lines: string[] = []; |
| 287 | const c = report.config, p = report.platform; |
| 288 | lines.push(`# Web feed report (${report.date.slice(0, 10)})`, ''); |
| 289 | lines.push(`corpus/${c.corpus}, ${c.count} bubbles, ${c.passes} passes per cell, \`step\` scroll (${Math.round(c.scroll.screenFraction |
| 290 | lines.push('Cells are median / p90. Per-bubble rows (warm time to content, blank, renderer ready, host constructor): over the bubbles of a pass, then the median across passes. Per-pass rows: across passes.', ''); |
| 291 | for (const t of tables(report)) { |
| 292 | lines.push(`## ${t.title}`, ''); |
| 293 | lines.push(`| | ${t.columns.map((col) => col.label).join(' | ')} |`); |
| 294 | lines.push(`|---|${t.columns.map(() => '---:').join('|')}|`); |
| 295 | let group: RowDef['group'] | null = null; |
| 296 | for (const row of report.rows) { |
| 297 | if (row.group !== group) { group = row.group; lines.push(`| **${GROUPS[group].label}** — ${GROUPS[group].claim} |${t.columns.map(() => |
| 298 | lines.push(`| ${row.label} | ${t.columns.map((col) => formatCell(col.combo.cells[row.key], row |
| 299 | } |
| 300 | lines.push(''); |
| 301 | const notes = [...new Set(t.columns.flatMap((col) => col.combo.notes))]; |
| 302 | if (notes.length) lines.push(...notes.map((n) => `- ${n}`), ''); |
| 303 | } |
| 304 | lines.push('Not measured: ' + report.notMeasured.join('; ') + '.', ''); |
| 305 | if (report.aborted) lines.push(`Run interrupted: ${report.aborted}`, ''); |
| 306 | return lines.join('\n'); |
| 307 | } |
| 308 | |
| 309 | // ───────────── the run ───────────── |
| 310 | |
| 311 | export interface BenchApi { |
| 312 | run(opts?: Partial<BenchOptions>): Promise<FeedReport>; |
| 313 | stop(): void; |
| 314 | readonly running: boolean; |
| 315 | /** The last (or current, while running) report. */ |
| 316 | readonly report: FeedReport | null; |
| 317 | markdown(): string; |
| 318 | json(): string; |
| 319 | download(): void; |
| 320 | readonly options: BenchOptions; |
| 321 | } |
| 322 | |
| 323 | export interface BenchHostOptions { |
| 324 | renderers: FeedRenderer[]; |
| 325 | params: URLSearchParams; |
| 326 | /** Show the panel (the `?bench=1` autorun opens it). */ |
| 327 | onOpen: () => void; |
| 328 | } |
| 329 | |
| 330 | // The product renderer (shadow) and the reference (iframe); the frozen canvas prototypes only through `combos`. |
| 331 | const DEFAULT_COMBOS: Combo[] = [ |
| 332 | { renderer: 'iframe', pool: true }, { renderer: 'shadow', pool: true }, |
| 333 | { renderer: 'iframe', pool: false }, { renderer: 'shadow', pool: false }, |
| 334 | ]; |
| 335 | |
| 336 | function parseCombos(text: string | null, renderers: FeedRenderer[]): Combo[] | null { |
| 337 | if (!text) return null; |
| 338 | const out: Combo[] = []; |
| 339 | for (const part of text.split(',')) { |
| 340 | const [r, p] = part.split(':'); |
| 341 | if (!renderers.includes(r as FeedRenderer)) continue; |
| 342 | out.push({ renderer: r as FeedRenderer, pool: p !== 'off' && p !== '0' }); |
| 343 | } |
| 344 | return out.length ? out : null; |
| 345 | } |
| 346 | |
| 347 | export function startBench(panel: HTMLElement, feed: FeedApi, host: BenchHostOptions): BenchApi { |
| 348 | const params = host.params; |
| 349 | const options: BenchOptions = { |
| 350 | passes: Math.max(1, Number(params.get('passes') ?? 5)), |
| 351 | count: Math.min(200, Math.max(1, Number(params.get('benchCount') ?? 60))), |
| 352 | corpus: (params.get('benchCorpus') === 'showcase' ? 'showcase' : 'common'), |
| 353 | combos: parseCombos(params.get('combos'), host.renderers) ?? DEFAULT_COMBOS, |
| 354 | prewarm: params.get('prewarm') !== '0', |
| 355 | settleMs: Math.max(0, Number(params.get('settle') ?? 1500)), |
| 356 | }; |
| 357 | let report: FeedReport | null = null; |
| 358 | let running = false; |
| 359 | let abort: string | null = null; |
| 360 | |
| 361 | // ───────────── panel ───────────── |
| 362 | |
| 363 | const el = (tag: string, cls = '', text = '') => { const e = |
| 364 | const form = el('div', 'bench-form'); |
| 365 | const passesInput = document.createElement('input'); |
| 366 | passesInput.type = 'number'; passesInput.min = '1'; passesInput.max = '20'; passesInput.value = String(options.passes); |
| 367 | passesInput.title = 'passes per renderer × pool cell; every cell is median / p90 over them'; |
| 368 | const countInput = document.createElement('input'); |
| 369 | countInput.type = 'number'; countInput.min = '4'; countInput.max = '200'; countInput.value = String(options.count); |
| 370 | countInput.title = 'widget bubbles per pass (a text bubble before every other one), the same for every cell'; |
| 371 | const comboBoxes: { combo: Combo; input: HTMLInputElement }[] = []; |
| 372 | const comboGrid = el('div', 'bench-combos'); |
| 373 | comboGrid.append(el('span', 'muted', ''), el('span', 'muted', 'pool on'), el('span', 'muted', 'pool off')); |
| 374 | for (const r of host.renderers) { |
| 375 | comboGrid.append(el('span', '', r)); |
| 376 | for (const pool of [true, false]) { |
| 377 | const label = el('label'); |
| 378 | const input = document.createElement('input'); |
| 379 | input.type = 'checkbox'; |
| 380 | input.checked = options.combos.some((c) => c.renderer === r && c.pool === pool); |
| 381 | label.appendChild(input); |
| 382 | comboGrid.appendChild(label); |
| 383 | comboBoxes.push({ combo: { renderer: r, pool }, input }); |
| 384 | } |
| 385 | } |
| 386 | const prewarmLabel = el('label'); |
| 387 | const prewarmInput = document.createElement('input'); |
| 388 | prewarmInput.type = 'checkbox'; prewarmInput.checked = options.prewarm; |
| 389 | prewarmLabel.title = 'fill the pool before the feed opens, as a messenger does at launch; off: the pool fills while the first screen boots'; |
| 390 | prewarmLabel.append(prewarmInput, ' prewarm pool before the feed opens'); |
| 391 | const runBtn = el('button', '', '▶ run') as HTMLButtonElement; |
| 392 | runBtn.type = 'button'; |
| 393 | const dlBtn = el('button', '', '⬇ JSON') as HTMLButtonElement; |
| 394 | dlBtn.type = 'button'; dlBtn.disabled = true; |
| 395 | dlBtn.title = 'feed-report-web.json: the same object the tables are rendered from (every boot, every long task total, every memory sample)'; |
| 396 | const mdBtn = el('button', '', '⎘ Markdown') as HTMLButtonElement; |
| 397 | mdBtn.type = 'button'; mdBtn.disabled = true; |
| 398 | mdBtn.title = 'copy the two tables as Markdown'; |
| 399 | const row1 = el('div', 'bench-row'); |
| 400 | row1.append(el('span', '', 'passes '), passesInput, el('span', '', ' bubbles '), countInput, el('span', 'muted', ` corpus/${options.corpus}, step scroll` |
| 401 | const row2 = el('div', 'bench-row'); |
| 402 | row2.append(runBtn, dlBtn, mdBtn); |
| 403 | form.append(row1, comboGrid, prewarmLabel, row2); |
| 404 | const progress = el('div', 'bench-progress muted', 'A pass: fresh pool (prewarmed) → reset → first screen settles → scripted scroll down and back → read out. Cells: median / p90.'); |
| 405 | const results = el('div', 'bench-results'); |
| 406 | panel.replaceChildren(el('div', 'bench-title', 'Measurements'), form, progress, results); |
| 407 | |
| 408 | runBtn.addEventListener('click', () => { if (running) stop(); else void run(); }); |
| 409 | dlBtn.addEventListener('click', download); |
| 410 | mdBtn.addEventListener('click', () => { void navigator.clipboard?.writeText(markdown()).then(() => setProgress('Markdown copied.')); }); |
| 411 | |
| 412 | function readForm(): Partial<BenchOptions> { |
| 413 | return { |
| 414 | passes: Math.max(1, Number(passesInput.value) || 5), |
| 415 | count: Math.min(200, Math.max(4, Number(countInput.value) || 60)), |
| 416 | combos: comboBoxes.filter((c) => c.input.checked).map((c) => c.combo), |
| 417 | prewarm: prewarmInput.checked, |
| 418 | }; |
| 419 | } |
| 420 | function setProgress(text: string, cls = 'muted') { progress.textContent = text; progress.className = 'bench-progress ' + cls; } |
| 421 | |
| 422 | // ───────────── collectors ───────────── |
| 423 | |
| 424 | /** Long tasks on the main thread and rAF intervals for one phase (the scripted scroll). */ |
| 425 | function phaseCollector() { |
| 426 | let longCount = 0, longTotal = 0, longMax = 0; |
| 427 | let observer: PerformanceObserver | null = null; |
| 428 | try { |
| 429 | observer = new PerformanceObserver((list) => { |
| 430 | for (const e of list.getEntries()) { longCount++; longTotal += e.duration; longMax = Math.max(longMax, e.duration); } |
| 431 | }); |
| 432 | observer.observe({ type: 'longtask', buffered: false }); |
| 433 | } catch { observer = null; } |
| 434 | const deltas: number[] = []; |
| 435 | let hiddenMs = 0, hiddenSince = document.hidden ? performance.now() : 0; |
| 436 | const onVis = () => { if (document.hidden) hiddenSince = performance.now(); else if (hiddenSince) { hiddenMs += performance.now() - hiddenSince; hiddenSince = 0; } }; |
| 437 | document.addEventListener('visibilitychange', onVis); |
| 438 | let last = 0, rafOn = true; |
| 439 | const tick = (t: number) => { |
| 440 | if (!rafOn) return; |
| 441 | if (last) deltas.push(t - last); |
| 442 | last = t; |
| 443 | requestAnimationFrame(tick); |
| 444 | }; |
| 445 | requestAnimationFrame(tick); |
| 446 | const started = performance.now(); |
| 447 | return { |
| 448 | stop(): { longTasks: PassResult['longTasks']; frames: PassResult['frames']; hiddenMs: number } { |
| 449 | rafOn = false; |
| 450 | document.removeEventListener('visibilitychange', onVis); |
| 451 | if (hiddenSince) hiddenMs += performance.now() - hiddenSince; |
| 452 | const seconds = (performance.now() - started) / 1000; |
| 453 | if (observer) { for (const e of observer.takeRecords()) { longCount++; longTotal += e.duration; longMax = Math.max(longMax, e.duration); } observer.disconnect(); } |
| 454 | // The display's refresh interval: the 20th percentile of the intervals (the quiet frames), snapped to 60 / 90 / 120 Hz. |
| 455 | const q20 = quantile(deltas, 0.2); |
| 456 | const hz = [60, 90, 120, 144].reduce((best, h) => (Math.abs(1000 / h - q20) |
| 457 | const expected = 1000 / hz; |
| 458 | let dropped = 0; |
| 459 | for (const d of deltas) dropped += Math.max(0, Math.round(d / expected) - 1); |
| 460 | return { |
| 461 | longTasks: { count: observer ? longCount : NaN, totalMs: observer ? longTotal : NaN, maxMs: observer ? longMax : NaN, scrollSeconds: seconds }, |
| 462 | frames: { count: deltas.length, expectedMs: expected, dropped, maxMs: deltas.length ? Math.max(...deltas) : NaN, p95Ms: quantile(deltas, 0.95), over32: deltas.filter((d) => d > 32).length |
| 463 | hiddenMs, |
| 464 | }; |
| 465 | }, |
| 466 | }; |
| 467 | } |
| 468 | |
| 469 | const liveCount = () => feed.bubbles.filter((b) => b.host).length; |
| 470 | const liveHeaps = () => feed.bubbles.reduce((a, b) => a + (b.host ? b.heap : 0), 0); |
| 471 | |
| 472 | // ───────────── the run ───────────── |
| 473 | |
| 474 | async function run(partial: Partial<BenchOptions> = {}): Promise<FeedReport> { |
| 475 | if (running) return report!; |
| 476 | Object.assign(options, readForm(), partial); |
| 477 | if (!options.combos.length) { setProgress('pick at least one renderer × pool cell', 'bad'); return report!; } |
| 478 | running = true; |
| 479 | abort = null; |
| 480 | runBtn.textContent = '■ stop'; |
| 481 | dlBtn.disabled = mdBtn.disabled = true; |
| 482 | const before = feed.settings; |
| 483 | const runStart = performance.now(); |
| 484 | const s = feed.settings; |
| 485 | report = { |
| 486 | kind: 'twidget-feed-report-web', |
| 487 | date: new Date().toISOString(), |
| 488 | userAgent: navigator.userAgent, |
| 489 | platform: { cores: navigator.hardwareConcurrency, dpr: devicePixelRatio, window: { width: innerWidth, height: innerHeight }, scroller: feed.viewport, theme: s.theme }, |
| 490 | config: { |
| 491 | corpus: options.corpus, count: options.count, passes: options.passes, prewarm: options.prewarm, settleMs: options.settleMs, |
| 492 | scroll: { kind: 'step', screenFraction: 0.9, pauseMs: 900 }, |
| 493 | lanes: s.lanes, ahead: s.ahead, keep: s.keep, poolSize: s.poolSize, hostile: 'none', |
| 494 | }, |
| 495 | rows: ROWS, |
| 496 | combos: [], |
| 497 | notMeasured: NOT_MEASURED, |
| 498 | totalSeconds: 0, |
| 499 | }; |
| 500 | feed.quiet(true); |
| 501 | try { |
| 502 | feed.clear(); |
| 503 | feed.setCorpus(options.corpus, false); |
| 504 | feed.setHostile('none', false); |
| 505 | feed.setCount(options.count, false); |
| 506 | for (const combo of options.combos) { |
| 507 | if (abort) break; |
| 508 | const result: ComboResult = { ...combo, key: `${combo.renderer}:${combo.pool ? 'on' : 'off'}`, passes: [], cells: {}, notes: [] }; |
| 509 | report.combos.push(result); |
| 510 | feed.setRenderer(combo.renderer); |
| 511 | for (let pass = 1; pass <= options.passes && !abort; pass++) { |
| 512 | setProgress(`${combo.renderer}, pool ${combo.pool ? 'on' : 'off'}: pass ${pass} / ${options.passes} …`, ''); |
| 513 | const p = await runPass(combo, pass); |
| 514 | if (!p) break; |
| 515 | result.passes.push(p); |
| 516 | result.cells = Object.fromEntries(ROWS.map((r) => [r.key, cell(r, result.passes)])); |
| 517 | result.notes = notesFor(result); |
| 518 | report.totalSeconds = (performance.now() - runStart) / 1000; |
| 519 | renderResults(); |
| 520 | } |
| 521 | } |
| 522 | } catch (e) { |
| 523 | abort = 'error: ' + String(e).split('\n')[0]; |
| 524 | } finally { |
| 525 | report.totalSeconds = (performance.now() - runStart) / 1000; |
| 526 | if (abort) report.aborted = abort; |
| 527 | running = false; |
| 528 | runBtn.textContent = '▶ run'; |
| 529 | dlBtn.disabled = mdBtn.disabled = !report.combos.some((c) => c.passes.length); |
| 530 | feed.quiet(false); |
| 531 | // Back to what the reader had before the run (one rebuild). |
| 532 | feed.setCorpus(before.corpus, false); |
| 533 | feed.setHostile(before.hostile, false); |
| 534 | feed.setCount(before.count, false); |
| 535 | feed.setRenderer(before.renderer); |
| 536 | feed.setPool(before.poolOn); |
| 537 | void feed.reset(); |
| 538 | renderResults(); |
| 539 | setProgress(abort ? `stopped: ${abort}` : `done in ${Math.round(report.totalSeconds)} s · ${report.combos.length} cells × ${options.passes |
| 540 | } |
| 541 | return report; |
| 542 | } |
| 543 | |
| 544 | /** One pass: fresh pool → reset → settle → scripted scroll → settle → read out. Null when stopped midway. */ |
| 545 | async function runPass(combo: Combo, pass: number): Promise<PassResult | null> { |
| 546 | const t0 = performance.now(); |
| 547 | feed.clear(); |
| 548 | feed.setPool(false); |
| 549 | if (combo.pool) { |
| 550 | feed.setPool(true); |
| 551 | if (options.prewarm) await feed.pool!.prewarm(); |
| 552 | } |
| 553 | if (abort) return null; |
| 554 | // Baseline: the empty feed, the pool warm — what a chat costs before any bubble (a second for the previous pass's processes and workers to go). |
| 555 | await sleep(1000); |
| 556 | const baseline = await measureMemory({ timeoutMs: 15_000, gc: true }); |
| 557 | const samples: PassResult['memory']['samples'] = []; |
| 558 | const procFn = (globalThis as any).__twProcessMemory; |
| 559 | let sampling = false; |
| 560 | const sampler = setInterval(async () => { |
| 561 | if (sampling) return; |
| 562 | sampling = true; |
| 563 | const m = (performance as any).memory; |
| 564 | const live = liveCount(), heaps = liveHeaps(), t = performance.now(); |
| 565 | // The process reading is the driver's (CDP + ps, off this thread); the live count is taken with it, before the await. |
| 566 | const process: number | null = typeof procFn === 'function' ? await procFn().catch(() => null |
| 567 | samples.push({ t, total: m ? (m.usedJSHeapSize as number) : null, process, live, heaps }); |
| 568 | sampling = false; |
| 569 | }, 1000); |
| 570 | try { |
| 571 | await feed.reset(); |
| 572 | await sleep(options.settleMs); |
| 573 | if (abort) return null; |
| 574 | const collector = phaseCollector(); |
| 575 | await feed.autoScroll(); |
| 576 | const phase = collector.stop(); |
| 577 | if (abort) return null; |
| 578 | await sleep(options.settleMs); |
| 579 | // The end reading: the live hosts of the top of the feed (the keep window) against the baseline, the same source as the baseline. |
| 580 | const end = await measureMemory({ precise: baseline.source === 'measureUserAgentSpecificMemory', timeoutMs: 15_000, gc: true }); |
| 581 | const liveAtEnd = liveCount(); |
| 582 | const records = feed.records.map((r) => ({ ...r })); |
| 583 | const ramp = await memoryRamp(); |
| 584 | return { |
| 585 | pass, |
| 586 | seconds: (performance.now() - t0) / 1000, |
| 587 | records, |
| 588 | incomplete: records.filter((r) => r.contentMs === null && !r.dead).length, |
| 589 | longTasks: phase.longTasks, |
| 590 | frames: phase.frames, |
| 591 | hiddenMs: phase.hiddenMs, |
| 592 | memory: { baseline, end, liveAtEnd, samples, ramp }, |
| 593 | pool: feed.pool ? { size: feed.pool.size, ...feed.pool.stats } : null, |
| 594 | }; |
| 595 | } finally { |
| 596 | clearInterval(sampler); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * The memory ramp: lift the drop distance, scroll through so every bubble boots and stays, read memory with all of them |
| 602 | * live against the reading just before (the keep window). The clocks and the boot records of the pass are closed by now. |
| 603 | */ |
| 604 | async function memoryRamp(): Promise<PassResult['memory']['ramp']> { |
| 605 | const t0 = performance.now(); |
| 606 | const pre = await measureMemory({ precise: false, gc: true }); |
| 607 | const livePre = liveCount(); |
| 608 | const keep = feed.settings.keep; |
| 609 | feed.setKeep(1000); |
| 610 | try { |
| 611 | const sc = feed.scroller; |
| 612 | const total = feed.bubbles.length; |
| 613 | for (let i = 0; i < 400 && !abort; i++) { |
| 614 | const atBottom = sc.scrollTop + sc.clientHeight >= sc.scrollHeight - 2; |
| 615 | if (atBottom && liveCount() >= total) break; |
| 616 | if (!atBottom) sc.scrollBy({ top: sc.clientHeight * 0.9, behavior: 'instant' as ScrollBehavior }); |
| 617 | await sleep(atBottom ? 250 : 150); |
| 618 | } |
| 619 | if (abort) return null; |
| 620 | await sleep(options.settleMs); |
| 621 | const all = await measureMemory({ precise: false, gc: true }); |
| 622 | return { pre, all, livePre, liveAll: liveCount(), heapsAll: liveHeaps(), seconds: (performance.now() - t0) / 1000 }; |
| 623 | } finally { |
| 624 | feed.setKeep(keep); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | function notesFor(c: ComboResult): string[] { |
| 629 | const notes: string[] = []; |
| 630 | const sources = new Set(c.passes.map((p) => p.memory.end.source)); |
| 631 | const procs = c.passes.some((p) => p.memory.end.process !== null); |
| 632 | notes.push(procs |
| 633 | ? 'memory per live bubble, browser processes: the ramp\'s delta in the RSS of every Chromium process (renderer, the isolated frames, GPU, utility; read by the driver) ÷ the bubbles that went live in it; the QuickJS workers and the renderer are both in it' |
| 634 | : 'memory per live bubble, browser processes: n/a — only the Playwright driver (scripts/feed-report.ts) can read process memory'); |
| 635 | const ramps = c.passes.map((p) => p.memory.ramp).filter((r): r is NonNullable<typeof r> => !!r); |
| 636 | if (ramps.length && ramps.some((r) => r.liveAll < options.count)) notes.push(`${c.renderer}, pool ${c.pool ? 'on' : |
| 637 | if (sources.has('none')) notes.push('page JS heap: n/a — no performance.memory in this browser'); |
| 638 | else if (sources.has('performance.memory')) notes.push('page JS heap: performance.memory with garbage included (no gc() in this browser); the QuickJS workers\' wasm memory and an isolated iframe\'s heap are not in it'); |
| 639 | else if (sources.has('performance.memory+gc')) notes.push('page JS heap: performance.memory after a forced gc(); the QuickJS workers\' wasm memory and an isolated iframe\'s heap are not in it'); |
| 640 | else notes.push('page JS heap row from measureUserAgentSpecificMemory: workers, frames and the page'); |
| 641 | const precise = c.passes.map((p) => p.memory.baseline.note).find(Boolean); |
| 642 | if (precise) notes.push(precise); |
| 643 | const incomplete = c.passes.reduce((a, p) => a + p.incomplete, 0); |
| 644 | if (incomplete) notes.push(`${c.renderer}, pool ${c.pool ? 'on' : 'off'}: ${incomplete} boots over ${c.passes.length} passes got no content (scrolled past or dropped while booting); they count in the blank row, not in time to content` |
| 645 | const dead = c.passes.reduce((a, p) => a + p.records.filter((r) => r.dead).length, 0); |
| 646 | if (dead) notes.push(`${c.renderer}, pool ${c.pool ? 'on' : 'off'}: ${dead} widgets stopped by the runtime limits`); |
| 647 | if (c.passes.some((p) => Number.isNaN(p.longTasks.totalMs))) notes.push('long tasks: PerformanceObserver longtask is not available in this browser'); |
| 648 | const hidden = c.passes.filter((p) => p.hiddenMs > 0); |
| 649 | if (hidden.length) notes.push(`${c.renderer}, pool ${c.pool ? 'on' : 'off'}: the tab was hidden during ${hidden.length} of ${c.passes |
| 650 | const misses = c.passes.reduce((a, p) => a + (p.pool?.misses ?? 0), 0); |
| 651 | if (c.pool && misses) notes.push(`${c.renderer}, pool on: the pool was empty ${misses} times over ${c.passes.length} passes (a fresh worker booted instead)`); |
| 652 | return notes; |
| 653 | } |
| 654 | |
| 655 | function stop() { if (running) abort = 'stopped by the reader'; feed.stop(); } |
| 656 | |
| 657 | // ───────────── output ───────────── |
| 658 | |
| 659 | function renderResults() { |
| 660 | results.replaceChildren(); |
| 661 | if (!report) return; |
| 662 | for (const t of tables(report)) { |
| 663 | results.appendChild(el('h3', '', t.title)); |
| 664 | const table = document.createElement('table'); |
| 665 | table.className = 'bench-table'; |
| 666 | const thead = document.createElement('tr'); |
| 667 | thead.appendChild(el('th', '', '')); |
| 668 | for (const col of t.columns) { |
| 669 | const th = el('th', '', col.label); |
| 670 | th.title = `${col.combo.passes.length} / ${options.passes} passes`; |
| 671 | if (col.combo.passes.length < options.passes) th.textContent += ` (${col.combo.passes.length}/${options.passes})`; |
| 672 | thead.appendChild(th); |
| 673 | } |
| 674 | table.appendChild(thead); |
| 675 | let group: RowDef['group'] | null = null; |
| 676 | for (const row of report.rows) { |
| 677 | if (row.group !== group) { |
| 678 | group = row.group; |
| 679 | const tr = document.createElement('tr'); |
| 680 | tr.className = 'bench-group'; |
| 681 | const td = el('td', '', GROUPS[group].label) as HTMLTableCellElement; |
| 682 | td.colSpan = t.columns.length + 1; |
| 683 | td.title = GROUPS[group].claim; |
| 684 | const claim = el('span', 'muted', ` — ${GROUPS[group].claim}`); |
| 685 | td.appendChild(claim); |
| 686 | tr.appendChild(td); |
| 687 | table.appendChild(tr); |
| 688 | } |
| 689 | const tr = document.createElement('tr'); |
| 690 | const label = el('td', '', row.label); |
| 691 | label.title = row.title; |
| 692 | tr.appendChild(label); |
| 693 | for (const col of t.columns) { |
| 694 | const c = col.combo.cells[row.key]; |
| 695 | const td = el('td', c ? '' : 'muted', formatCell(c, row.unit)); |
| 696 | if (c) td.title = `${c.n} samples · ${row.kind === 'bubble' ? 'median / p90 over bubbles, the median across passes' : 'median / p90 across passes'}`; |
| 697 | tr.appendChild(td); |
| 698 | } |
| 699 | table.appendChild(tr); |
| 700 | } |
| 701 | results.appendChild(table); |
| 702 | const notes = [...new Set(t.columns.flatMap((col) => col.combo.notes))]; |
| 703 | for (const n of notes) results.appendChild(el('div', 'bench-note muted', n)); |
| 704 | } |
| 705 | if (report.combos.some((c) => c.passes.length)) { |
| 706 | const c = report.config, p = report.platform; |
| 707 | results.appendChild(el('div', 'bench-note', `Method: corpus/${c.corpus}, ${c.count} bubbles, ${c.passes} passes per cell, step scroll (90 % of a screen, pause 900 ms, down and back), pool ×${c.poolSize}${c.prewarm |
| 708 | results.appendChild(el('div', 'bench-note muted', 'Not measured: ' + report.notMeasured.join('; ') + '.')); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | function json() { return JSON.stringify(report, (_k, v) => (typeof v === 'number' ? (Number.isFinite(v) ? Math.round(v |
| 713 | function markdown() { return report ? toMarkdown(report) : ''; } |
| 714 | function download() { |
| 715 | if (!report) return; |
| 716 | const blob = new Blob([json()], { type: 'application/json' }); |
| 717 | const a = document.createElement('a'); |
| 718 | a.href = URL.createObjectURL(blob); |
| 719 | a.download = `feed-report-web-${report.date.slice(0, 19).replace(/[:T]/g, '-')}.json`; |
| 720 | a.click(); |
| 721 | setTimeout(() => URL.revokeObjectURL(a.href), 1000); |
| 722 | } |
| 723 | |
| 724 | // `?bench=1`: open the panel and run with the URL's options (the Playwright driver scripts/feed-report.ts uses __tw.feed.bench.run instead). |
| 725 | if (params.get('bench') === '1') { host.onOpen(); setTimeout(() => void run(), 500); } |
| 726 | else if (params.get('bench') === 'open') host.onOpen(); |
| 727 | |
| 728 | return { |
| 729 | run, stop, markdown, json, download, |
| 730 | get running() { return running; }, |
| 731 | get report() { return report; }, |
| 732 | get options() { return options; }, |
| 733 | }; |
| 734 | } |
| 735 | |