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

Merged opened this

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

Merged

scout/forge:scout/16302-the-signed-in-feed-s-first-paint-answers → main 0 commits fork 2 threads · 2 unresolved

  • Merged. scout/16302-the-signed-in-feed-s-first-paint-answers was merged into main as f7b9291.

Review

Sign in to review this change.
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 () => {
6262 expect(names).toEqual(expect.arrayContaining(["app", "session", "feed", "render"]));
6363 });
6464
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
7565 test("the first thirty posts are in the HTML, and no script fetches them", async () => {
7666 const { html } = await look("/feed");
7767 const cards = html.match(/data-item=/g) ?? [];
@@ -89,9 +79,32 @@ test("GET / names its read-total and render phases in Server-Timing", async () =
8979 expect(names).toEqual(expect.arrayContaining(["read-total", "render"]));
9080 });
9181
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 }
outdated

Duplicate of BUDGET_MS (line 18). Keep one constant.

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);
97110 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs