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

opened this

Merged 35h 5m ago, live in production

fix/pull-budget-counted → main 0 commits

  • Merged. fix/pull-budget-counted was merged into main as 73c1fa5.

Review

Sign in to review this change.
2 files changed +24 −21
src/perf/page_budgets/pull.ts +2 −2
@@ -4,6 +4,6 @@ import type { PageBudget } from "../page_budget.ts";
44 // by test/page-budget.test.ts. Measured there on 2026-11-21, three runs: 109 SQL statements warm
55 // every run, CPU median 10.3–11.6 ms; 104 statements and a median of 14 ms on a loaded host after
66 // 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).
99 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 @@
11 /**
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.
55 */
66 import { afterAll, beforeAll, expect, test } from "bun:test";
77 import { mkdtemp, rm } from "node:fs/promises";
@@ -15,25 +15,19 @@ import { submitReview } from "../src/core/reviews.ts";
1515 import { createSession } from "../src/core/sessions.ts";
1616 import { createUser } from "../src/core/users.ts";
1717 import { serve, type Servers } from "../src/http/server.ts";
18 import { budget } from "../src/perf/page_budgets/pull.ts";
1918 import { quietLogs } from "./helpers/globals.ts";
2019 import { statements } from "./helpers/statements.ts";
20 import { gitSpawns } from "./helpers/work.ts";
2121
2222 quietLogs();
2323
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;
3124 /**
3225 * The statements one warm request runs. A new query fails the test; raise it on purpose. 111: the
3326 * open secrets pushed to the head branch (#17048, `openSecretsOn`, one read of a partial index).
3427 */
3528 const STATEMENTS = 111;
36 const RUNS = 30;
29 /** How many warm answers the git count samples. */
30 const COUNTED = 5;
3731
3832 let dataDir: string;
3933 let app: App;
@@ -95,14 +89,23 @@ async function appPhase(): Promise<number> {
9589 return Number(m![1]);
9690 }
9791
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 () => {
10298 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);
106109 });
107110
108111 test(`the pull page runs exactly ${STATEMENTS} SQL statements`, async () => {

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs