Public: anyone can read this; the crew can change it.
The warm pull page's budget is counted work: no git process spawned, and its statements, not a stopwatch #17266
Merged 35h 5m ago, live in production
fix/pull-budget-counted → main 0 commits
2 files
changed +24
−21
src/perf/page_budgets/pull.ts +2 −2
| @@ -4,6 +4,6 @@ import type { PageBudget } from "../page_budget.ts"; | ||
| 4 | 4 | // by test/page-budget.test.ts. Measured there on 2026-11-21, three runs: 109 SQL statements warm |
| 5 | 5 | // every run, CPU median 10.3–11.6 ms; 104 statements and a median of 14 ms on a loaded host after |
| 6 | 6 | // the head's wall and log came from memory (#10539, `keptRead`). Statements: the count plus a tenth |
| 7 | // (it does not move with load; a doubling is an N+1). Median: half the 25 ms it was held to, the | |
| 8 | // bound test/pull-budget.test.ts also reads, so one budget holds this page. | |
| 7 | // (it does not move with load; a doubling is an N+1). Median: half the 25 ms it was held to. | |
| 8 | // test/pull-budget.test.ts counts the warm page's work instead (no git spawned, its statements). | |
| 9 | 9 | export const budget: PageBudget = { page: "a pull", pattern: "/:owner/:name/pulls/:number", medianMs: 12.5, statements: 115 }; |
test/pull-budget.test.ts +22 −19
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | /** |
| 2 | * The pull page's budget, measured on a pull with 20 files, 5 reviews and 3 checks (#10539): | |
| 3 | * its server time through `Server-Timing` (the `app` phase, as test/feed-budget.test.ts reads it) | |
| 4 | * and its SQL statements, fixed so a new query fails here and is raised on purpose. | |
| 2 | * The pull page's budget, measured on a pull with 20 files, 5 reviews and 3 checks (#10539), as | |
| 3 | * counted work: the git processes a warm answer spawns (none) and its SQL statements, fixed so a | |
| 4 | * new query fails here and is raised on purpose. | |
| 5 | 5 | */ |
| 6 | 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 7 | 7 | import { mkdtemp, rm } from "node:fs/promises"; |
| @@ -15,25 +15,19 @@ import { submitReview } from "../src/core/reviews.ts"; | ||
| 15 | 15 | import { createSession } from "../src/core/sessions.ts"; |
| 16 | 16 | import { createUser } from "../src/core/users.ts"; |
| 17 | 17 | import { serve, type Servers } from "../src/http/server.ts"; |
| 18 | import { budget } from "../src/perf/page_budgets/pull.ts"; | |
| 19 | 18 | import { quietLogs } from "./helpers/globals.ts"; |
| 20 | 19 | import { statements } from "./helpers/statements.ts"; |
| 20 | import { gitSpawns } from "./helpers/work.ts"; | |
| 21 | 21 | |
| 22 | 22 | quietLogs(); |
| 23 | 23 | |
| 24 | /** | |
| 25 | * The warm `app` phase, ms: the shared budget (src/perf/page_budgets/pull.ts), the one bound for | |
| 26 | * this page. Before: floor 10.5 ms, median 13.8 ms, 111 statements; after the head's wall and log | |
| 27 | * are read from memory (`keptRead`): floor 8.3 ms. The fastest of 30 is judged, so a loaded | |
| 28 | * machine has to be slow every time to fail it: 4 ms of headroom over the floor. | |
| 29 | */ | |
| 30 | const BUDGET_MS = budget.medianMs; | |
| 31 | 24 | /** |
| 32 | 25 | * The statements one warm request runs. A new query fails the test; raise it on purpose. 111: the |
| 33 | 26 | * open secrets pushed to the head branch (#17048, `openSecretsOn`, one read of a partial index). |
| 34 | 27 | */ |
| 35 | 28 | const STATEMENTS = 111; |
| 36 | const RUNS = 30; | |
| 29 | /** How many warm answers the git count samples. */ | |
| 30 | const COUNTED = 5; | |
| 37 | 31 | |
| 38 | 32 | let dataDir: string; |
| 39 | 33 | let app: App; |
| @@ -95,14 +89,23 @@ async function appPhase(): Promise<number> { | ||
| 95 | 89 | return Number(m![1]); |
| 96 | 90 | } |
| 97 | 91 | |
| 98 | // The fastest of the warm answers is judged, not the median: a loaded machine only ever adds to a | |
| 99 | // sample (the median of 21 ran 11-36 ms on one idle code path), while work the page does on every | |
| 100 | // request, a git spawn or a lost cache, is in every sample, so the fastest still shows it. | |
| 101 | test(`the pull page answers warm in under ${BUDGET_MS} ms (20 files, 5 reviews, 3 checks)`, async () => { | |
| 92 | // What a warm pull page costs is counted, not timed (`helpers/work.ts`): the old timed version | |
| 93 | // failed on unrelated pulls and verify runs under runner load (eight checks on 2026-12-01, #16997 | |
| 94 | // to #17252; #17266), and passed alone. What the clock stood for is countable: the page's | |
| 95 | // head wall and log come from memory (`keptRead`, #10539), so a warm answer spawns no git process, | |
| 96 | // and its queries are pinned below. A page that loses its cache spawns git, or queries, every time. | |
| 97 | test("a warm pull page spawns no git process (20 files, 5 reviews, 3 checks)", async () => { | |
| 102 | 98 | await appPhase(); |
| 103 | const runs: number[] = []; | |
| 104 | for (let i = 0; i < RUNS; i++) runs.push(await appPhase()); | |
| 105 | expect(Math.min(...runs)).toBeLessThan(BUDGET_MS); | |
| 99 | // The git record is the process's: another worker's spawn can land in a window. The fewest of | |
| 100 | // COUNTED warm answers is judged; a page that lost its cache spawns in every one. | |
| 101 | const spawns: number[] = []; | |
| 102 | for (let i = 0; i < COUNTED; i++) | |
| 103 | spawns.push( | |
| 104 | await gitSpawns(async () => { | |
| 105 | await appPhase(); | |
| 106 | }), | |
| 107 | ); | |
| 108 | expect(Math.min(...spawns)).toBe(0); | |
| 106 | 109 | }); |
| 107 | 110 | |
| 108 | 111 | test(`the pull page runs exactly ${STATEMENTS} SQL statements`, async () => { |
new above
offline