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

A stranger's way to a forge answers under budget: /pricing, /forges/new and /claim join the page-load budget #11414

Merged opened this

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

Merged

torque/forge:torque/11410-a-stranger-s-way-to-a-forge-answers-unde → main 1 commit fork

  • Merged. torque/11410-a-stranger-s-way-to-a-forge-answers-unde was merged into main as 1356189.

Review

Sign in to review this change.
2 files changed +29 −8
src/perf/page_budget.ts +7
@@ -20,6 +20,8 @@ export interface PageBudget {
2020 readonly medianMs: number;
2121 /** One warm request runs at most this many SQL statements. */
2222 readonly statements: number;
23 /** Walked with no cookie: a stranger's page, not a signed-in person's. */
24 readonly signedOut?: true;
2325 }
2426
2527 /** Statement limits are today's count, signed in, plus a little: lower them as pages get cheaper, raise one only on purpose. */
@@ -29,6 +31,11 @@ export const PAGE_BUDGETS: readonly PageBudget[] = [
2931 { page: "map", pattern: "/map", medianMs: 50, statements: 21 },
3032 { page: "an app page", pattern: "/:owner/:name", medianMs: 50, statements: 49 },
3133 { page: "changelog", pattern: "/changelog", medianMs: 50, statements: 20 },
34 // A stranger's way to a forge (#11410): walked signed out. `/claim` is
35 // measured on a spawned forge with a live link, as the child's owner sees it.
36 { page: "pricing", pattern: "/pricing", medianMs: 50, statements: 10, signedOut: true },
37 { page: "new forge", pattern: "/forges/new", medianMs: 50, statements: 14, signedOut: true },
38 { page: "claim", pattern: "/claim", medianMs: 50, statements: 14, signedOut: true },
3239 ];
3340
3441 /** The path a budget's pattern names for one repository: `:owner` and `:name` filled, everything else as written. */
test/page-budget.test.ts +22 −8
@@ -15,6 +15,8 @@ import { tmpdir } from "node:os";
1515 import { join } from "node:path";
1616 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1717 import { createApp, type App } from "../src/app.ts";
18 import { createOrg } from "../src/core/orgs.ts";
19 import { mintClaim } from "../src/spawn/claim.ts";
1820 import { createIssue } from "../src/core/issues.ts";
1921 import { getRepo } from "../src/core/repos.ts";
2022 import { createUser, type User } from "../src/core/users.ts";
@@ -73,6 +75,11 @@ beforeAll(async () => {
7375 const made = createIssue(app.db, { repoId: notes.id, authorId: bob.id, title: `Issue ${i}`, body: "body" });
7476 if (!made.ok) throw new Error(made.error);
7577 }
78 // A spawned forge with a live claim link, so `/claim` shows its form.
79 const kin = createOrg(app.db, "kin", alice.id);
80 if (!kin.ok) throw new Error(kin.error);
81 await Bun.write(join(root, "parent.json"), JSON.stringify({ org: "kin" }));
82 mintClaim(app.db, kin.value.id);
7683 servers = await serve(app);
7784 const signin = await fetch(`${servers.url}/signin`, {
7885 method: "POST",
@@ -90,8 +97,8 @@ afterAll(() => {
9097 rmSync(root, { recursive: true, force: true });
9198 });
9299
93 /** Every page is walked as alice, signed in: the map asks for a viewer. */
94 const INIT = (): RequestInit => ({ headers: { cookie }, redirect: "manual" });
100 /** Pages are walked as alice, signed in (the map asks for a viewer); a stranger's pages (`signedOut`) with no cookie. */
101 const init = (b: PageBudget): RequestInit => (b.signedOut ? { redirect: "manual" } : { headers: { cookie }, redirect: "manual" });
95102
96103 function url(b: PageBudget): string {
97104 return `${servers.url}${pagePath(b, "alice", "notes")}`;
@@ -99,14 +106,14 @@ function url(b: PageBudget): string {
99106
100107 /** One request warms; then the fewest statements of `COUNTED` warm requests is the count, so a background tick's queries do not land on a page. */
101108 async function count(b: PageBudget): Promise<{ status: number; statements: number; phases: PageMeasure["phases"] }> {
102 const first = await fetch(url(b), INIT());
109 const first = await fetch(url(b), init(b));
103110 await first.arrayBuffer();
104111 let status = first.status;
105112 let header = "";
106113 let fewest = Number.POSITIVE_INFINITY;
107114 for (let i = 0; i < COUNTED; i++) {
108115 const n = await statements(app.db, async () => {
109 const res = await fetch(url(b), INIT());
116 const res = await fetch(url(b), init(b));
110117 await res.arrayBuffer();
111118 status = res.status;
112119 header = res.headers.get("server-timing") ?? "";
@@ -119,12 +126,12 @@ async function count(b: PageBudget): Promise<{ status: number; statements: numbe
119126
120127 /** One warm-up, then `TIMED` timed requests; the phases are the last request's. */
121128 async function time(b: PageBudget): Promise<{ samples: number[]; phases: PageMeasure["phases"] }> {
122 await (await fetch(url(b), INIT())).arrayBuffer();
129 await (await fetch(url(b), init(b))).arrayBuffer();
123130 const samples: number[] = [];
124131 let header = "";
125132 for (let i = 0; i < TIMED; i++) {
126133 const t = performance.now();
127 const res = await fetch(url(b), INIT());
134 const res = await fetch(url(b), init(b));
128135 await res.arrayBuffer();
129136 samples.push(performance.now() - t);
130137 header = res.headers.get("server-timing") ?? "";
@@ -132,14 +139,21 @@ async function time(b: PageBudget): Promise<{ samples: number[]; phases: PageMea
132139 return { samples, phases: parsePhases(header) };
133140 }
134141
135 test("the budget table names five pages, each once, with a median and a statement limit", () => {
136 expect(PAGE_BUDGETS.map((b) => b.pattern)).toEqual(["/", "/explore", "/map", "/:owner/:name", "/changelog"]);
142 test("the budget table names eight pages, each once, with a median and a statement limit", () => {
143 expect(PAGE_BUDGETS.map((b) => b.pattern)).toEqual([
144 "/", "/explore", "/map", "/:owner/:name", "/changelog", "/pricing", "/forges/new", "/claim",
145 ]);
137146 for (const b of PAGE_BUDGETS) {
138147 expect(b.medianMs).toBeLessThanOrEqual(50);
139148 expect(Number.isInteger(b.statements) && b.statements > 0).toBe(true);
140149 }
141150 });
142151
152 test("a stranger's way to a forge is on the list, walked signed out", () => {
153 const strangers = PAGE_BUDGETS.filter((b) => b.signedOut).map((b) => b.pattern);
154 expect(strangers).toEqual(["/pricing", "/forges/new", "/claim"]);
155 });
156
143157 test("each first page runs no more SQL statements warm than its budget", async () => {
144158 const findings: string[] = [];
145159 const table: string[] = [];

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs