Public: anyone can read this; the crew can change it.

The space page has a page budget, so a slow space view fails the check as a slow map does #12779

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/12770-the-space-page-has-a-page-budget-so-a-sl → main 2 commits fork

  • Merged. torque/12770-the-space-page-has-a-page-budget-so-a-sl was merged into main as 74160be.

Review

Sign in to review this change.
4 files changed +112 −2
docs/design/size-budget.json +8
@@ -23,6 +23,14 @@
2323 "js": 23040,
2424 "css": 44032
2525 },
26 "/:owner/:name/space": {
27 "js": 28672,
28 "css": 44800
29 },
30 "/:owner/:name/space.json": {
31 "js": 0,
32 "css": 0
33 },
2634 "/pricing": {
2735 "js": 21248,
2836 "css": 43520
src/perf/page_budget.ts +5
@@ -32,6 +32,11 @@ export const PAGE_BUDGETS: readonly PageBudget[] = [
3232 { page: "an app page", pattern: "/:owner/:name", medianMs: 50, statements: 49 },
3333 { page: "changelog", pattern: "/changelog", medianMs: 50, statements: 20 },
3434 { page: "next up", pattern: "/:owner/:name/next", medianMs: 50, statements: 64 },
35 // The space (#12770), which the owner opens to watch growth: the page and the
36 // `space.json` it reads are two requests, so each has its own row.
37 // Statement limits: measured warm (15 and 6) plus two, the margin the map row keeps.
38 { page: "space", pattern: "/:owner/:name/space", medianMs: 50, statements: 17 },
39 { page: "space data", pattern: "/:owner/:name/space.json", medianMs: 50, statements: 8 },
3540 // A stranger's way to a forge (#11410): walked signed out. `/claim` is
3641 // measured on a spawned forge with a live link, as the child's owner sees it.
3742 { page: "pricing", pattern: "/pricing", medianMs: 50, statements: 10, signedOut: true },
test/page-budget.test.ts +3 −2
@@ -154,9 +154,10 @@ async function time(
154154 return { samples, walls, phases: parsePhases(header) };
155155 }
156156
157 test("the budget table names nine pages, each once, with a median and a statement limit", () => {
157 test("the budget table names eleven pages, each once, with a median and a statement limit", () => {
158158 expect(PAGE_BUDGETS.map((b) => b.pattern)).toEqual([
159 "/", "/explore", "/map", "/:owner/:name", "/changelog", "/:owner/:name/next", "/pricing", "/forges/new", "/claim",
159 "/", "/explore", "/map", "/:owner/:name", "/changelog", "/:owner/:name/next",
160 "/:owner/:name/space", "/:owner/:name/space.json", "/pricing", "/forges/new", "/claim",
160161 ]);
161162 for (const b of PAGE_BUDGETS) {
162163 expect(b.medianMs).toBeLessThanOrEqual(50);
test/space-budget.test.ts added +96
@@ -0,0 +1,96 @@
1 /**
2 * The space has a page budget (#12770): the page and the `space.json` it reads
3 * each run no more SQL statements warm than their rows in
4 * `src/perf/page_budget.ts`, on the fixture the map tests seed. Statements,
5 * not the clock, are judged: they are the same on a loaded machine.
6 * `test/page-budget.test.ts` also walks both rows for the median.
7 */
8 import { afterAll, beforeAll, expect, test } from "bun:test";
9 import { mkdtempSync, rmSync } from "node:fs";
10 import { tmpdir } from "node:os";
11 import { join } from "node:path";
12 import { seedFixture, type Fixture, type Shape } from "../bench/map-home.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { clearMapCache } from "../src/web/map_cache.ts";
15 import { countFinding, pagePath, PAGE_BUDGETS } from "./helpers/page_budget.ts";
16 import { quietLogs } from "./helpers/globals.ts";
17 import { statements } from "./helpers/statements.ts";
18
19 quietLogs();
20
21 const SMALL: Shape = {
22 repos: 3, bigIssues: 40, bigOpen: 12, bigGraph: 20, bigEdges: 24, bigPulls: 2,
23 lanes: [5, 3], privateLanes: 1, sealed: 1, runs: 2, comments: 1, events: 50,
24 };
25
26 let dir = "";
27 let f: Fixture;
28 let servers: Servers;
29
30 beforeAll(async () => {
31 dir = mkdtempSync(join(tmpdir(), "forge-space-budget-"));
32 clearMapCache();
33 f = await seedFixture(dir, SMALL);
34 servers = await serve(f.app);
35 }, 120_000);
36 afterAll(() => {
37 servers?.stop();
38 f?.app.close();
39 rmSync(dir, { recursive: true, force: true });
40 });
41
42 const row = (pattern: string) => PAGE_BUDGETS.find((b) => b.pattern === pattern)!;
43
44 /**
45 * Warm the page once, then the fewest statements of five warm requests,
46 * plus a hook that runs inside each.
47 */
48 async function count(pattern: string, extra?: () => void): Promise<number> {
49 const b = row(pattern);
50 const path = pagePath(b, "keeper", "forge");
51 const hit = async () => {
52 const res = await fetch(`${servers.url}${path}`, { headers: { cookie: f.ownerCookie } });
53 await res.arrayBuffer();
54 expect(res.status).toBe(200);
55 extra?.();
56 };
57 await hit();
58 return statements(f.app.db, hit);
59 }
60
61 test("the space page and its space.json each have a row, with the median and a statement limit", () => {
62 for (const p of ["/:owner/:name/space", "/:owner/:name/space.json"]) {
63 const b = row(p);
64 expect(b).toBeDefined();
65 expect(b.medianMs).toBeLessThanOrEqual(50);
66 expect(b.statements).toBeGreaterThan(0);
67 }
68 });
69
70 test("the space page runs no more SQL statements than its row", async () => {
71 const b = row("/:owner/:name/space");
72 const n = await count(b.pattern);
73 expect(countFinding(b, { status: 200, statements: n, samples: [], phases: [] })).toBeUndefined();
74 });
75
76 test("the space.json read runs no more SQL statements than its row", async () => {
77 const b = row("/:owner/:name/space.json");
78 const n = await count(b.pattern);
79 expect(countFinding(b, { status: 200, statements: n, samples: [], phases: [] })).toBeUndefined();
80 });
81
82 test("a statement added to either request is named: the margin is two, not more", async () => {
83 for (const pattern of ["/:owner/:name/space", "/:owner/:name/space.json"]) {
84 const b = row(pattern);
85 const base = await count(pattern);
86 expect(b.statements - base).toBeLessThanOrEqual(2);
87 // Three more statements per request, as an N+1 would add, breaks the row.
88 const more = await count(pattern, () => {
89 for (let i = 0; i < 3; i++) f.app.db.query("SELECT 1").get();
90 });
91 expect(more).toBe(base + 3);
92 expect(countFinding(b, { status: 200, statements: more, samples: [], phases: [] })).toContain(
93 `${more} SQL statements, budget ${b.statements}`,
94 );
95 }
96 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs