diff --git a/bench/README.md b/bench/README.md index cbf97c7778d..503336e2200 100644 --- a/bench/README.md +++ b/bench/README.md @@ -479,7 +479,7 @@ reconnects x 64 characters, and keeps its run directory as the `bench-browser` artifact. The in-memory frame, retained-history, gap ledger, bandwidth allocation, cached-group -replay, and resume-history paths also run directly in Chromium: +replay, resume-history, and buffered-group paths also run directly in Chromium: ```bash nix develop --command bun bench/browser/micro.ts --bench frames --out .tmp/frames.json base=/path/to/release current=. aa=. @@ -488,6 +488,7 @@ nix develop --command bun bench/browser/micro.ts --bench ledger --out .tmp/ledge nix develop --command bun bench/browser/micro.ts --bench bandwidth --out .tmp/bandwidth.json before=/path/to/main current=. aa=. nix develop --command bun bench/browser/micro.ts --bench replay --out .tmp/replay.json before=/path/to/main current=. aa=. nix develop --command bun bench/browser/micro.ts --bench resume-history --out .tmp/resume-history.json before=/path/to/main current=. aa=. +nix develop --command bun bench/browser/micro.ts --bench buffered --out .tmp/buffered.json before=/path/to/main current=. aa=. ``` Each variant uses its own workspace source and a persistent, cross-origin isolated @@ -514,6 +515,15 @@ Its `time_mode` column is 0 for untimed, 1 for millisecond timestamps, and 2 for mixed millisecond/microsecond timestamps, which exercise exact cross-scale comparison. +`buffered` drives every checkout's `@moq/hang` container consumer with one fixture, +sweeping buffered groups against frames per group, then publishers against players. +`steady` reads each frame as it lands (its `ns_per_op` is the frame delay); +`lookahead` and `sparse` decode every group before draining them, in order or +shuffled with a missing sequence between groups; `burst` times only the arrival +that skips every buffered group once the max delay drops to zero, per skipped group. +Each case checks its exact buffered ranges, timestamp order and payloads, and that +skipped groups are closed; `gaps` and `warnings` must match between variants. + `replay` sweeps retained groups (64, 512, 2048) against subscribers (1, 8) for monotonic, reverse, and shuffled arrivals. `join` rows time each subscriber joining the cache and replaying every retained group; `append` rows time each of @@ -542,8 +552,8 @@ route hold, from Chromium's precise memory info; `serve_us` and `read_us` include no setup. Bun's collector scans its stack conservatively, so the fixture refuses to run there. -The browser smoke lane preserves one measured round of all six fixtures, and drift, -ledger, bandwidth and replay also run in the nightly JS benchmark leg. Timing is +The browser smoke lane preserves one measured round of all seven fixtures, and drift, +ledger, bandwidth, replay and buffered also run in the nightly JS benchmark leg. Timing is observational, with the A/A spread showing the host's noise floor. ## Pattern and container coverage diff --git a/bench/browser/micro.ts b/bench/browser/micro.ts index cb5c6b4edd2..e993dfcd245 100644 --- a/bench/browser/micro.ts +++ b/bench/browser/micro.ts @@ -23,9 +23,12 @@ const benchmarks: Record = { bandwidth: { entry: "js/net/bench/bandwidth.ts", rows: 44 }, replay: { entry: "js/net/bench/replay.ts", rows: 72 }, "resume-history": { entry: "js/net/bench/resume-history.ts", rows: 72 }, + buffered: { entry: "js/hang/bench/buffered.ts", rows: 36 }, }; const selected = Object.hasOwn(benchmarks, benchmark) ? benchmarks[benchmark] : undefined; if (!selected) throw new Error(`--bench must be one of: ${Object.keys(benchmarks).join(", ")}`); +// The fixture directory, relative to each checkout; buffered drives @moq/hang's container consumer. +const dir = benchmark === "buffered" ? "js/hang/bench" : "js/net/bench"; const rounds = Number(values.rounds); if (!Number.isSafeInteger(rounds) || rounds < 1) throw new Error("--rounds must be a positive integer"); const roots = new Map(); @@ -49,12 +52,10 @@ for (const [name, root] of roots) { setup(build) { // Internal modules have no package export, so select each variant's own explicitly. build.onResolve({ filter: /^\.\.\/src\// }, ({ path, importer }) => - importer.endsWith(`/js/net/bench/${benchmark}.ts`) - ? { path: resolve(root, "js/net/bench", path) } - : undefined, + importer.endsWith(`/${dir}/${benchmark}.ts`) ? { path: resolve(root, dir, path) } : undefined, ); build.onLoad( - { filter: /\/bench\/(frames|drift|ledger|bandwidth|replay|resume-history)\.ts$/ }, + { filter: /\/bench\/(frames|drift|ledger|bandwidth|replay|resume-history|buffered)\.ts$/ }, async ({ path }) => { const source = await Bun.file(path).text(); if (benchmark !== "frames") @@ -126,7 +127,8 @@ try { pages.set(name, page); rows.set(name, []); page.on("console", (message) => { - if (/^(lite|ietf|\d+),/.test(message.text())) rows.get(name)?.push(message.text()); + if (/^(lite|ietf|steady|lookahead|sparse|burst|\d+),/.test(message.text())) + rows.get(name)?.push(message.text()); }); page.on("pageerror", (error) => { console.error(error); diff --git a/bench/browser/run.sh b/bench/browser/run.sh index ca8d613244c..3f4c2b3409b 100755 --- a/bench/browser/run.sh +++ b/bench/browser/run.sh @@ -88,7 +88,7 @@ bun install --frozen-lockfile cd "$HERE" # The in-memory paths share Chromium installation and artifact retention with this lane. -for benchmark in frames drift ledger bandwidth replay resume-history; do +for benchmark in frames drift ledger bandwidth replay resume-history buffered; do bun micro.ts --bench "$benchmark" --rounds 1 --out "$HARNESS_RUN/$benchmark.json" \ current="$WORKSPACE" aa="$WORKSPACE" done diff --git a/js/hang/bench/buffered.ts b/js/hang/bench/buffered.ts new file mode 100644 index 00000000000..25eaad8d607 --- /dev/null +++ b/js/hang/bench/buffered.ts @@ -0,0 +1,219 @@ +/** Sweep buffered groups, frames per group, publishers and players through the container consumer. */ +import { Milli } from "@moq/clock"; +import { type Group, Time, Track, Varint } from "@moq/net"; +import { Signal } from "@moq/signals"; +import { Consumer } from "../src/container/consumer.ts"; +import { Format } from "../src/container/legacy.ts"; + +// Far past every fixture's span, so only the burst case skips anything. +const HOLD = Milli(1_000_000_000); +// One group per second at 30 fps. +const FRAME_US = 33_333; +const GROUP_US = 1_000_000; +const PAYLOAD = new Uint8Array([7]); +// Measured operations per case, repeating smaller ones. +const MIN_OPS = 8192; + +type Scenario = "steady" | "lookahead" | "sparse" | "burst"; + +interface Player { + track: Track.Producer; + consumer: Consumer; + // Every group the consumer received, to check that what it skipped is closed. + received: Group.Consumer[]; +} + +function timestamp(group: number, frame: number): number { + return group * GROUP_US + frame * FRAME_US; +} + +function payload(group: number, frame: number): Uint8Array { + const prefix = Varint.encode(timestamp(group, frame)); + const data = new Uint8Array(prefix.byteLength + PAYLOAD.byteLength); + data.set(prefix, 0); + data.set(PAYLOAD, prefix.byteLength); + return data; +} + +function wire(group: number, frame: number): Group.Frame { + return { payload: payload(group, frame), timestamp: Time.Timestamp.fromMicros(timestamp(group, frame)) }; +} + +function open(track: Track.Producer, delay: Signal): Player { + const subscriber = track.subscribe({ delay: { max: HOLD } }); + const received: Group.Consumer[] = []; + const recv = subscriber.recvGroup.bind(subscriber); + subscriber.recvGroup = async () => { + const group = await recv(); + if (group) received.push(group); + return group; + }; + return { track, consumer: new Consumer(subscriber, { format: new Format("video"), delay }), received }; +} + +// The deterministic arrival order of the sparse case: every group exactly once, shuffled. +function shuffled(count: number): number[] { + const order = Array.from({ length: count }, (_, i) => i); + let seed = 42; + for (let i = count - 1; i > 0; i--) { + seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; + const j = seed % (i + 1); + [order[i], order[j]] = [order[j], order[i]]; + } + return order; +} + +// Write one frame to every publisher, then wait until every player decoded it, as each arrival would +// be decoded before the next lands. A decoded frame always changes some buffered range. +async function arrive(groups: Group.Producer[], players: Player[], index: number, frame: number): Promise { + const changed = players.map((player) => player.consumer.buffered.changed()); + for (const group of groups) group.writeFrame(wire(index, frame)); + await Promise.all(changed); +} + +// Read every buffered frame, checking timestamp order, and count the gaps between them. +async function drain(player: Player, expected: number[]): Promise { + let gaps = 0; + for (const want of expected) { + for (;;) { + const read = await player.consumer.next(); + if (!read) throw new Error("frame missing"); + if (read.kind === "gap") { + gaps++; + continue; + } + if (read.kind !== "frame" || read.frame.timestamp !== want || read.frame.payload[0] !== PAYLOAD[0]) + throw new Error("frame missing or reordered"); + break; + } + } + return gaps; +} + +function ranges(player: Player): string { + return JSON.stringify(player.consumer.buffered.peek()); +} + +/** Return elapsed ns, the measured operations, gaps and warnings for one case. */ +async function measure( + scenario: Scenario, + groups: number, + frames: number, + publishers: number, + readers: number, +): Promise<{ ns: number; ops: number; gaps: number; warnings: number }> { + const delay = new Signal({ max: HOLD }); + // Stamped like a hang publisher's media, so the transport finds its live edge at the newest group. + const tracks = Array.from({ length: publishers }, (_, i) => + new Track.Producer(`p${i}`).accept({ timescale: Time.Timescale.MICRO }), + ); + const players = tracks.flatMap((track) => Array.from({ length: readers }, () => open(track, delay))); + let warnings = 0; + const warn = console.warn; + console.warn = () => { + warnings++; + }; + try { + const sequence = (i: number) => (scenario === "sparse" ? i * 2 : i); + const order = scenario === "sparse" ? shuffled(groups) : Array.from({ length: groups }, (_, i) => i); + const expected = Array.from({ length: groups * frames }, (_, i) => + timestamp(sequence(Math.floor(i / frames)), i % frames), + ); + let gaps = 0; + let start = performance.now(); + if (scenario === "steady") { + // The player reads each frame as it lands, so nothing builds up behind it. + for (const i of order) { + const sources = tracks.map((track) => track.createGroup(i)); + for (let frame = 0; frame < frames; frame++) { + const reads = players.map((player) => player.consumer.next()); + for (const source of sources) source.writeFrame(wire(i, frame)); + for (const read of await Promise.all(reads)) + if (read?.kind !== "frame" || read.frame.timestamp !== timestamp(i, frame)) + throw new Error("frame missing or reordered"); + } + for (const source of sources) source.finish(); + } + return { ns: (performance.now() - start) * 1e6, ops: groups * frames * players.length, gaps, warnings }; + } + + // Everything arrives before the player reads: a stalled reader, or history after a join. + for (const i of order) { + const sources = tracks.map((track) => track.createGroup(sequence(i))); + for (let frame = 0; frame < frames; frame++) await arrive(sources, players, sequence(i), frame); + for (const source of sources) source.finish(); + } + // A finished track proves no missing group can still arrive. + if (scenario === "sparse") for (const track of tracks) track.finish(); + await Promise.resolve(); + + for (const player of players) { + // Finished adjacent groups merge into one range; sparse ones stay one range per group. + const want = + scenario === "sparse" + ? Array.from({ length: groups }, (_, i) => ({ + start: timestamp(sequence(i), 0) / 1000, + end: timestamp(sequence(i), frames - 1) / 1000, + })) + : [{ start: 0, end: timestamp(groups - 1, frames - 1) / 1000 }]; + if (ranges(player) !== JSON.stringify(want)) throw new Error(`wrong buffered ranges: ${ranges(player)}`); + } + + if (scenario === "burst") { + // The budget drops to nothing, so the next arrival makes every older group too stale to keep. + delay.set({ max: Milli.zero }); + start = performance.now(); + const sources = tracks.map((track) => track.createGroup(groups)); + await arrive(sources, players, groups, 0); + const elapsed = (performance.now() - start) * 1e6; + const newest = timestamp(groups, 0) / 1000; + for (const player of players) { + if (ranges(player) !== JSON.stringify([{ start: newest, end: newest }])) + throw new Error(`skip left ${ranges(player)}`); + if (player.received.slice(0, groups).some((group) => !group.isClosed)) + throw new Error("skipped group left open"); + const read = await player.consumer.next(); + if (read?.kind !== "frame" || read.frame.timestamp !== timestamp(groups, 0)) + throw new Error("newest frame missing"); + } + return { ns: elapsed, ops: groups * players.length, gaps, warnings }; + } + + for (const player of players) gaps += await drain(player, expected); + return { ns: (performance.now() - start) * 1e6, ops: groups * frames * players.length, gaps, warnings }; + } finally { + console.warn = warn; + for (const player of players) player.consumer.close(); + for (const track of tracks) track.close(); + } +} + +/** + * Print one CSV row per case. `ns_per_op` is per frame and player, except for a burst, where it is per + * skipped group and player and covers only the arrival that skips them. + */ +export async function run(): Promise { + console.log("scenario,groups,frames,publishers,players,ops,gaps,warnings,ns_per_op"); + const cases: [Scenario, number, number, number, number][] = []; + for (const scenario of ["steady", "lookahead", "sparse", "burst"] as const) + for (const groups of [1, 16, 256, 1024]) + for (const frames of [1, 30]) cases.push([scenario, groups, frames, 1, 1]); + for (const publishers of [1, 4]) + for (const players of [1, 8]) cases.push(["lookahead", 64, 30, publishers, players]); + for (const [scenario, groups, frames, publishers, players] of cases) { + // Small cases repeat, so a coarse browser clock still resolves them. + const total = { ns: 0, ops: 0, gaps: 0, warnings: 0 }; + while (total.ops < MIN_OPS) { + const { ns, ops, gaps, warnings } = await measure(scenario, groups, frames, publishers, players); + total.ns += ns; + total.ops += ops; + total.gaps += gaps; + total.warnings += warnings; + } + console.log( + `${scenario},${groups},${frames},${publishers},${players},${total.ops},${total.gaps},${total.warnings},${(total.ns / total.ops).toFixed(0)}`, + ); + } +} + +if (import.meta.main) await run(); diff --git a/js/hang/src/container/consumer.skips.test.ts b/js/hang/src/container/consumer.skips.test.ts index 94820a9e44b..9bb0075244a 100644 --- a/js/hang/src/container/consumer.skips.test.ts +++ b/js/hang/src/container/consumer.skips.test.ts @@ -139,3 +139,49 @@ test("a backlog start waits on a successor without frames", async () => { warn.mockRestore(); } }); + +test("Consumer measures each skip's span over every group left, not just the new oldest", async () => { + const warn = spyOn(console, "warn").mockImplementation(() => {}); + const track = new Track.Producer("tone"); + const delay = new Signal({ max: Milli(30_000) }); + const consumer = new Consumer(track.subscribe({ delay: { max: Milli(30_000) } }), { + format: new Format("data"), + delay, + }); + const write = (sequence: number, timestamp: number) => { + const group = track.createGroup(sequence); + group.writeFrame({ payload: Varint.encode(timestamp), timestamp: Time.Timestamp.now() }); + }; + const buffered = async (timestamp: number) => { + while (consumer.buffered.peek().at(-1)?.end !== timestamp) await consumer.buffered.changed(); + }; + try { + // Group 2 starts below group 1, so the span after skipping group 0 still reaches back to it. + for (const [sequence, timestamp] of [ + [0, 0], + [1, 10_000], + [2, 1_000], + [3, 12_000], + ]) + write(sequence, timestamp); + await buffered(12); + // Reading the first frame warms the reader, so the age skip runs on the max delay alone. + expect(await consumer.next()).toMatchObject({ kind: "frame", group: 0 }); + delay.set({ max: Milli(5) }); + write(4, 13_000); + await buffered(13); + expect(warn).toHaveBeenLastCalledWith("skipping slow groups: track=tone 0 -> 3 count=3"); + expect(consumer.buffered.peek()).toEqual([ + { start: Milli(12), end: Milli(12) }, + { start: Milli(13), end: Milli(13) }, + ]); + // The skipped groups held media past the first frame, so their span reads as a gap first. + expect(await consumer.next()).toMatchObject({ kind: "gap", timestamp: 0, duration: 12_000 }); + expect(await consumer.next()).toMatchObject({ kind: "frame", group: 3 }); + } finally { + consumer.close(); + track.finish(); + track.close(); + warn.mockRestore(); + } +}); diff --git a/js/hang/src/container/consumer.ts b/js/hang/src/container/consumer.ts index d29782d52c0..39db92fb250 100644 --- a/js/hang/src/container/consumer.ts +++ b/js/hang/src/container/consumer.ts @@ -115,6 +115,12 @@ interface Group { released?: boolean; // Dropped from #groups, with what it held refunded } +// The earliest and latest known frame timestamps of the buffered groups from each index on. +interface Spans { + min: (number | undefined)[]; + max: (number | undefined)[]; +} + // Two adjacent groups are treated as timeline-contiguous when the next group's first PTS is within // this slack of the current group's end. Per-sample durations and base-decode-times are each rounded // to microseconds independently, so a genuinely contiguous boundary can be off by ~1µs (seen on 48kHz @@ -478,6 +484,8 @@ export class Consumer { let skipped = 0; const start = this.#groups[0]?.consumer.sequence; + // The span left after each further skip, computed once the first skip shows more may follow. + let spans: Spans | undefined; // Keep skipping the oldest group while the buffered span exceeds the max delay. // This also handles gaps in group sequence numbers: if #active points to a missing @@ -490,12 +498,20 @@ export class Consumer { let min: number | undefined; let max: number | undefined; - for (const group of this.#groups) { - if (group.latest === undefined) continue; + if (skipped === 0) { + for (const group of this.#groups) { + if (group.latest === undefined) continue; - const frame = group.frames.at(0)?.timestamp ?? group.latest; - if (min === undefined || frame < min) min = frame; - if (max === undefined || group.latest > max) max = group.latest; + const frame = group.frames.at(0)?.timestamp ?? group.latest; + if (min === undefined || frame < min) min = frame; + if (max === undefined || group.latest > max) max = group.latest; + } + } else { + // A skip removes only the oldest group, so one pass over what the first skip left gives + // the span after every later one, and a bulk skip stays linear in the buffered groups. + spans ??= this.#spans(); + min = spans.min[skipped - 1]; + max = spans.max[skipped - 1]; } if (min === undefined || max === undefined) break; @@ -510,7 +526,8 @@ export class Consumer { // Before the first item, a backlog that landed whole starts within the budget, so only // the group covering the live edge less the reach is kept: one whose successor starts // past that point. Rust's start skip, in `Consumer::poll_event_once`, measures the same. - const target = this.#startTarget(this.#reach(this.#delay.peek())); + // `max` is the live edge of the groups left, so this stays O(1) per skip. + const target = this.#startTarget(this.#reach(this.#delay.peek()), max); if (target !== undefined && nextStart > target) break; } else if (max - nextStart < threshold) { // Once reading began, it is stale only once its successor starts a whole budget behind @@ -554,6 +571,26 @@ export class Consumer { return skipped > 0; } + // The earliest and latest known frames of the buffered groups from each index on: the span left + // once that many of the oldest groups are skipped, undefined where none of them has a frame. + #spans(): Spans { + const count = this.#groups.length; + const spans: Spans = { min: new Array(count), max: new Array(count) }; + let min: number | undefined; + let max: number | undefined; + for (let i = count - 1; i >= 0; i--) { + const group = this.#groups[i]; + if (group.latest !== undefined) { + const frame = group.frames.at(0)?.timestamp ?? group.latest; + if (min === undefined || frame < min) min = frame; + if (max === undefined || group.latest > max) max = group.latest; + } + spans.min[i] = min; + spans.max[i] = max; + } + return spans; + } + // Skip the stalled active group once it has presented up to where the next group // begins (its furthest frame end reaches the next group's first timestamp). Only // fires when the active group is fully consumed and still open, so we never drop @@ -944,14 +981,21 @@ export class Consumer { // The point the start reaches back to: the live edge (the newest content) less `reach`. Undefined // for a zero reach, which the newest group covers, and before any timed content, since untimed // content such as a marker has no edge to reach back from. - #startTarget(reach: number): number | undefined { + // A caller that already knows the live edge passes it, sparing a scan of every group. + #startTarget(reach: number, known?: number): number | undefined { if (reach === 0) return undefined; + const edge = known ?? this.#liveEdge(); + // Media starts at zero, so a reach past it is covered there. + return edge === undefined ? undefined : Math.max(0, edge - reach); + } + + // The newest known frame timestamp across the buffered groups. + #liveEdge(): number | undefined { let edge: number | undefined; for (const group of this.#groups) { if (group.latest !== undefined && (edge === undefined || group.latest > edge)) edge = group.latest; } - // Media starts at zero, so a reach past it is covered there. - return edge === undefined ? undefined : Math.max(0, edge - reach); + return edge; } // How stale the buffered span may get before the age skip drops its oldest group, in microseconds: diff --git a/js/justfile b/js/justfile index 07865bbd705..fbc65ad98f9 100644 --- a/js/justfile +++ b/js/justfile @@ -150,6 +150,11 @@ slow-group-bench: bun install --frozen-lockfile bun hang/bench/slow-group.ts +# Sweep a hang consumer's buffered groups, frames per group, publishers and players across arrival orders. +buffered-bench: + bun install --frozen-lockfile + bun hang/bench/buffered.ts + # Sweep the audio jitter estimator's held history against in-order and reordered frames. jitter-bench: bun install --frozen-lockfile diff --git a/quest/m2/audit-perf.md b/quest/m2/audit-perf.md index 54c1da9da72..ec0ae144ed3 100644 --- a/quest/m2/audit-perf.md +++ b/quest/m2/audit-perf.md @@ -165,22 +165,20 @@ follow-up quest. The m1 run added none of these: renditions and window segments. 2. LOC and CMAF wire containers in moq-mux: `containers` and `export` only use `Container::Legacy`; sweep container x frame size x frames. -3. [Buffered browser groups](/quest/m2/performance-survey/hang-buffered.md) - owns per-frame scans and bulk skip work in the Hang consumer. -4. [Browser media copies](/quest/m2/performance-survey/browser-media-copies.md) +3. [Browser media copies](/quest/m2/performance-survey/browser-media-copies.md) owns CMAF sample copies and LOC encode allocation. Generic `js/msf` and `js/flate` benchmark coverage remains here. -5. moq-quic loss recovery and real congestion controllers: every bench pins +4. moq-quic loss recovery and real congestion controllers: every bench pins `Unlimited`; sweep controller x flight x loss x streams. -6. [Announcement snapshots](/quest/m2/performance-survey/announced-snapshots.md) +5. [Announcement snapshots](/quest/m2/performance-survey/announced-snapshots.md) owns HTTP snapshot/rendering costs across routes and pollers. -7. JWT verification is covered: `moq-auth`'s `verify` bench runs nightly in +6. JWT verification is covered: `moq-auth`'s `verify` bench runs nightly in `rust-extra` (see [bench/README.md](/bench/README.md#auth-verification)). Signature verification dominated every asymmetric algorithm; nothing was changed. Track its `decide`, `set` and `sessions` series here. -8. MPEG-TS import with real repeated media (the CLI bench mostly skips null +7. MPEG-TS import with real repeated media (the CLI bench mostly skips null padding), and MKV, FLV, H.265, AV1 importers. -9. JS watch audio ring buffer and publish `Fanout` (lower impact). Include +8. JS watch audio ring buffer and publish `Fanout` (lower impact). Include capture-to-encoder staging: `audio/framer.ts` copies planes before `audio/encoder.ts` joins them. AudioData already uses a transfer list; do not count that transfer as another mandatory copy. Sweep publishers @@ -190,7 +188,7 @@ The [2026-10-22 source survey](/quest/m2/performance-survey/README.md) owns the extracted items above and additional algorithmic hypotheses, with paired benchmarks required before optimization. This audit still owns nightly regression attribution and the remaining coverage. Its fragmented-MKV child -specializes item 8's MKV work. +specializes item 7's MKV work. Single-axis fan-out benches to widen: `session_delivery_paced` (viewers only), `track_fanout_*` (subscribers only), `memory` (lite-06 only), and diff --git a/quest/m2/performance-survey/README.md b/quest/m2/performance-survey/README.md index 3a86cd37016..11be7a70dfb 100644 --- a/quest/m2/performance-survey/README.md +++ b/quest/m2/performance-survey/README.md @@ -210,7 +210,6 @@ The `js/replay` nightly series and the browser smoke's `replay.json` protect it. - [Cache metadata](/quest/m2/performance-survey/cache-metadata.md) - bookkeeping capacity after cached groups expire - [PCM batch processing](/quest/m2/performance-survey/audio-batches.md) - repeated tail movement during encoding and resampling - [HLS request fan-out](/quest/m2/performance-survey/hls-serving.md) - repeated fetch, remux and playlist construction per viewer -- [Buffered browser groups](/quest/m2/performance-survey/hang-buffered.md) - per-frame scans and bulk skip work - [Idle browser stats](/quest/m2/performance-survey/browser-idle-stats.md) - local transport polling without active publishing demand - [Announcement snapshots](/quest/m2/performance-survey/announced-snapshots.md) - HTTP polling cost versus result size and unrelated routes - [Selective session operations](/quest/m2/performance-survey/session-selection.md) - exact-ID lookups and registry lock hold time diff --git a/quest/m2/performance-survey/hang-buffered.md b/quest/m2/performance-survey/hang-buffered.md deleted file mode 100644 index 59baf68ad66..00000000000 --- a/quest/m2/performance-survey/hang-buffered.md +++ /dev/null @@ -1,30 +0,0 @@ -# [M] Browser buffered-group bookkeeping scales with changed data - -## Goal - -Playing or skipping buffered groups avoids avoidable repeated backlog scans -without changing the buffering and max-delay contract. - -## Plan - -[Hang Consumer](/js/hang/src/container/consumer.ts) rebuilds buffered ranges -by walking groups in `#updateBuffered` (line 696). `#checkMaxDelay` scans -all groups inside a loop that shifts old groups (line 377), so bulk skipping -can repeat the scan. These paths execute while frames arrive and are read. - -Add real-browser cases sweeping buffered groups × frames per group, then -players × independent publishers. Compare ordinary steady playback, sparse -out-of-order groups, large lookahead and a burst that must be skipped. -Measure operation counts, main-thread CPU, allocations/GC and frame delay. -Verify exact buffered ranges, gaps, timestamp order, skip decisions and closure -of discarded frames. Incremental extrema/ranges are candidates only if their -maintenance is cheaper across normal and adversarial arrival orders. - -This extracts the recurring audit's buffered-consumer finding. -[Watch worker planning](/quest/m2/plan-watch-worker.md) owns main-thread -isolation; moving the work does not discharge this algorithmic measurement. - -Follow the [survey's benchmark contract](/quest/m2/performance-survey/README.md): -measure the baseline before optimizing, retain paired evidence, verify equivalent -work, schedule coverage nightly, and accept a measured no-win. Expected public -API and wire impact: none; report the actual impact in the implementation PR. diff --git a/sh/gh/nightly.sh b/sh/gh/nightly.sh index 30fa14f8392..37dc9c2ac90 100755 --- a/sh/gh/nightly.sh +++ b/sh/gh/nightly.sh @@ -156,6 +156,7 @@ case "$1" in javascript json-codec just js json-codec-bench javascript json-parse just js json-parse-bench javascript slow-group just js slow-group-bench + javascript buffered just js buffered-bench javascript jitter just js jitter-bench javascript audio-warmup just js audio-warmup-bench javascript audio-support just js audio-support-bench diff --git a/sh/gh/nightly.test.py b/sh/gh/nightly.test.py index a3e88f90fe2..c0076dc4e1c 100644 --- a/sh/gh/nightly.test.py +++ b/sh/gh/nightly.test.py @@ -193,13 +193,16 @@ def test_every_js_bench_runs_nightly(self): continue for path in recipes[args[2]]: entries.add(ROOT / "js" / path.replace("{{ name }}", args[-1])) - # The browser smoke lane runs the in-memory net fixtures in Chromium. + # The browser smoke lane runs the in-memory fixtures in Chromium. self.assertIn("recipe: bench-browser --smoke", workflow) smoke = re.search( r"^for benchmark in (.+); do\n\s+bun micro\.ts ", (ROOT / "bench/browser/run.sh").read_text(), re.M ) self.assertIsNotNone(smoke) - entries |= {ROOT / "js/net/bench" / f"{name}.ts" for name in smoke[1].split()} + for name in smoke[1].split(): + fixtures = list((ROOT / "js").glob(f"*/bench/{name}.ts")) + self.assertEqual(len(fixtures), 1, f"browser smoke bench {name}") + entries |= set(fixtures) # Bundled helpers only run through the entry that names them. helpers = { path for entry in entries for path in entry.parent.glob("*.ts") if f"/{path.name}" in entry.read_text()