Public: anyone can read this; the crew can change it.
The signed-in feed's first paint answers under 50 ms warm, measured by a test that fails above it #16599
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16302-the-signed-in-feed-s-first-paint-answers → main 0 commits fork 2 threads · 2 unresolved
1 file
changed +28
−15
test/feed-budget.test.ts +28 −15
| @@ -62,16 +62,6 @@ test("GET /feed names its stretches in Server-Timing", async () => { | ||
| 62 | 62 | expect(names).toEqual(expect.arrayContaining(["app", "session", "feed", "render"])); |
| 63 | 63 | }); |
| 64 | 64 | |
| 65 | test("the warm first paint holds the budget", async () => { | |
| 66 | await look("/feed"); | |
| 67 | const runs: number[] = []; | |
| 68 | for (let i = 0; i < 3; i++) { | |
| 69 | const { timing } = await look("/feed"); | |
| 70 | runs.push(Number(/(?:^|, )app;dur=([\d.]+)/.exec(timing)![1])); | |
| 71 | } | |
| 72 | expect(Math.min(...runs)).toBeLessThan(BUDGET_MS); | |
| 73 | }); | |
| 74 | ||
| 75 | 65 | test("the first thirty posts are in the HTML, and no script fetches them", async () => { |
| 76 | 66 | const { html } = await look("/feed"); |
| 77 | 67 | const cards = html.match(/data-item=/g) ?? []; |
| @@ -89,9 +79,32 @@ test("GET / names its read-total and render phases in Server-Timing", async () = | ||
| 89 | 79 | expect(names).toEqual(expect.arrayContaining(["read-total", "render"])); |
| 90 | 80 | }); |
| 91 | 81 | |
| 92 | test("GET / with 500 posts: the median of three warm answers is under 50 ms", async () => { | |
| 93 | await look("/"); | |
| 94 | const runs: number[] = []; | |
| 95 | for (let i = 0; i < 3; i++) runs.push(Number(/(?:^|, )app;dur=([\d.]+)/.exec((await look("/")).timing)![1])); | |
| 96 | expect(median(runs)).toBeLessThan(BUDGET_MS); | |
| 82 | // The budget stated once more for the page and its JSON (#16302): the median of nine warm answers, | |
| 83 | // the server's own `app` phase, over a feed of hundreds of items. A median so one slow tick on a | |
| 84 | // loaded machine does not fail it, while a lost index (which costs every run) still does. | |
| 85 | const RUNS = 9; | |
| 86 | ||
| 87 | async function appPhase(path: string): Promise<number> { | |
| 88 | const res = await fetch(`${servers.url}${path}`, { headers: { cookie } }); | |
| 89 | expect(res.status).toBe(200); | |
| 90 | await res.arrayBuffer(); | |
| 91 | const m = /(?:^|, )app;dur=([\d.]+)/.exec(res.headers.get("server-timing") ?? ""); | |
| 92 | expect(m).not.toBeNull(); | |
| 93 | return Number(m![1]); | |
| 94 | } | |
| 95 | ||
| 96 | for (const path of ["/", "/feed", "/api/v1/feed"]) { | |
| 97 | test(`GET ${path}: the median of ${RUNS} warm answers is under ${BUDGET_MS} ms`, async () => { | |
| 98 | await appPhase(path); // cold | |
| 99 | const runs: number[] = []; | |
| 100 | for (let i = 0; i < RUNS; i++) runs.push(await appPhase(path)); | |
| 101 | expect(median(runs)).toBeLessThan(BUDGET_MS); | |
| 102 | }); | |
| 103 | } | |
| 104 | ||
| 105 | test("GET /api/v1/feed returns a first page of items, not the whole feed", async () => { | |
| 106 | const res = await fetch(`${servers.url}/api/v1/feed`, { headers: { cookie } }); | |
| 107 | const body = (await res.json()) as { items: unknown[] }; | |
| 108 | expect(body.items.length).toBeGreaterThan(0); | |
| 109 | expect(body.items.length).toBeLessThan(SEEDED); | |
| 97 | 110 | }); |
new above
offline
Duplicate of BUDGET_MS (line 18). Keep one constant.