#!/usr/bin/env tsx // What the three-second status poll costs, over the live corpus. // // `/api/auto-queue/status` folds one `buildKind()` per lane, and the whole of // `buildKind`'s cost is `computeLeafPending` — which reads and parses every // channel snapshot the lane's projection touches. Slice 1.2 makes the digest // and backfill lanes draw their operation union by default, so two lanes that // read nothing start reading all 68 snapshots twice a tick. This is the meter // that says whether the parse memo in `readChannelSnapshot` paid for itself. // // STRICTLY READ-ONLY, and offline: no editor, no runner, no snapshot regen. // Usage, from anywhere in the repo: // pnpm --filter yt-dlp-transcript-common exec tsx ../plans/tools/phase1-poll-timing.ts // // ROUNDS=n to change the sample count (default 3). Round 1 is cold — an empty // memo and a cold page cache — and the rounds after it are what a poll running // every three seconds actually pays. import { getPaths } from "../../common/lib/paths"; import { computeLeafPending } from "../../common/controller/autoRunner"; import { resetChannelSnapshotMemo } from "../../common/controller/channels"; import { LANES, type AutoQueueKind } from "../../common/lib/autoQueueTypes"; const paths = getPaths(); const ROUNDS = Number(process.env.ROUNDS ?? 3); // NOMEMO=1 drops the parse memo before every round — what the poll would cost // without it, which is the comparison the memo has to justify. const NOMEMO = process.env.NOMEMO === "1"; for (let round = 0; round < ROUNDS; round++) { if (NOMEMO) resetChannelSnapshotMemo(); const started = Date.now(); const per: string[] = []; // Promise.all over the lanes, exactly as buildAutoQueueStatusPayload folds them. await Promise.all( LANES.map(async (lane: AutoQueueKind) => { const at = Date.now(); const pending = await computeLeafPending(lane, paths); const total = Object.values(pending.counts).reduce((a, b) => a + b, 0); per.push(`${lane}=${Date.now() - at}ms/${total}`); }), ); console.log( `round ${round + 1}: total ${Date.now() - started}ms [${per.sort().join(" ")}]`, ); }