From fbabdfbe15b1a425745b3e633d6f4c4114e3cbb4 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Sat, 18 Jul 2026 22:16:23 -0400 Subject: [PATCH] bench(tui): add per-append timing series mode to streaming-md bench --- ui-tui/scripts/bench-streaming-md.tsx | 32 ++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/ui-tui/scripts/bench-streaming-md.tsx b/ui-tui/scripts/bench-streaming-md.tsx index 30a9127ac1612..3655969db92b8 100644 --- a/ui-tui/scripts/bench-streaming-md.tsx +++ b/ui-tui/scripts/bench-streaming-md.tsx @@ -189,7 +189,12 @@ const nullStream = () => { return s } -const bench = (label: string, updates: string[], node: (t: typeof DEFAULT_THEME, text: string) => React.ReactNode) => { +const bench = ( + label: string, + updates: string[], + node: (t: typeof DEFAULT_THEME, text: string) => React.ReactNode, + captureSeries = false +) => { // Fresh theme per run → fresh (collectable) mdCache bucket. const runTheme = { ...DEFAULT_THEME } @@ -200,13 +205,20 @@ const bench = (label: string, updates: string[], node: (t: typeof DEFAULT_THEME, stdout: nullStream() as unknown as NodeJS.WriteStream }) + const times: number[] = [] const start = performance.now() let n = 0 for (const text of updates) { + const t0 = captureSeries ? performance.now() : 0 + instance.rerender(node(runTheme, text)) + if (captureSeries) { + times.push(performance.now() - t0) + } + // Something in the render path emits performance measures; unbounded, // the entry buffer itself becomes a memory leak over thousands of // rerenders and skews long runs. @@ -221,7 +233,7 @@ const bench = (label: string, updates: string[], node: (t: typeof DEFAULT_THEME, instance.unmount() instance.cleanup() - return { elapsed, label } + return { elapsed, label, times } } const STRATEGIES = { @@ -232,7 +244,21 @@ const STRATEGIES = { const [strategyArg, sizeArg] = process.argv.slice(2) -if (strategyArg) { +if (strategyArg === 'series') { + // Series mode: per-append render times for one strategy/size, as JSON. + // Usage: npx tsx scripts/bench-streaming-md.tsx series + const [, seriesStrategy, seriesSize] = process.argv.slice(2) + const size = Number(seriesSize) + const updates = makeUpdates(makeBlocks(size, `${seriesStrategy}${size}`)) + const { elapsed, times } = bench( + seriesStrategy!, + updates, + STRATEGIES[seriesStrategy as keyof typeof STRATEGIES], + true + ) + + console.log(JSON.stringify({ appends: updates.length, elapsed, times })) +} else if (strategyArg) { // Child mode: run one strategy/size and print elapsed ms as JSON. const size = Number(sizeArg) const updates = makeUpdates(makeBlocks(size, `${strategyArg}${size}`))