Public: anyone can read this; the crew can change it.
The palette ranks 2,000 rows in under 50 ms, timed in a test #10720
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/10708-the-palette-ranks-2-000-rows-in-under-50 → main 1 commit fork
1 file
changed +47
−0
test/palette-rows.test.ts +47
| @@ -104,3 +104,50 @@ test("2,000 rows: the number lands first and the list stays capped", () => { | ||
| 104 | 104 | expect(hits.flatMap((g) => g.rows).length).toBeLessThanOrEqual(20); |
| 105 | 105 | expect(rankPalette(rows, "roof 17", [], 20).flatMap((g) => g.rows).length).toBeLessThanOrEqual(20); |
| 106 | 106 | }); |
| 107 | ||
| 108 | const median = (xs: number[]) => xs.slice().sort((a, b) => a - b)[Math.floor(xs.length / 2)]!; | |
| 109 | const timeMs = (run: () => void) => { | |
| 110 | const runs: number[] = []; | |
| 111 | for (let n = 0; n < 5; n++) { | |
| 112 | const t0 = performance.now(); | |
| 113 | run(); | |
| 114 | runs.push(performance.now() - t0); | |
| 115 | } | |
| 116 | return median(runs); | |
| 117 | }; | |
| 118 | ||
| 119 | test("2,000 rows: a number, a word and two words each rank in under 50 ms (median of 5)", () => { | |
| 120 | const rows: PaletteRow[] = Array.from({ length: 2000 }, (_, i) => ({ | |
| 121 | t: `Issue title number ${i} about the roof`, | |
| 122 | h: `/o/n/issues/${i + 1}`, | |
| 123 | g: "Issues", | |
| 124 | d: `#${i + 1} opened by someone`, | |
| 125 | k: i + 1, | |
| 126 | })); | |
| 127 | rankPalette(rows, "roof", [], 20); // warm the JIT: the ceiling is for the steady state | |
| 128 | const slowest = Math.max( | |
| 129 | timeMs(() => rankPalette(rows, "#1234", [], 20)), | |
| 130 | timeMs(() => rankPalette(rows, "roof", [], 20)), | |
| 131 | timeMs(() => rankPalette(rows, "title roof", [], 20)), | |
| 132 | ); | |
| 133 | expect(slowest).toBeLessThan(50); | |
| 134 | }); | |
| 135 | ||
| 136 | test("every row kind is found by its own words", () => { | |
| 137 | const rows: PaletteRow[] = [ | |
| 138 | { t: "Leaky gutter on the barn", h: "/o/n/issues/7", g: "Issues", d: "#7", k: 7 }, | |
| 139 | { t: "Repaint the fence", h: "/o/n/pulls/8", g: "Pull requests", d: "#8", k: 8 }, | |
| 140 | { t: "pablo", h: "/pablo", g: "People" }, | |
| 141 | { t: "Change password", h: "/settings/password", g: "Settings" }, | |
| 142 | { t: "Tell the crew", h: "/o/n/tell", g: "Actions", a: 1 }, | |
| 143 | { t: "Unrelated", h: "/x", g: "Pages" }, | |
| 144 | ]; | |
| 145 | const top = (q: string) => rankPalette(rows, q, [], 5)[0]?.rows[0]?.h; | |
| 146 | expect(top("gutter barn")).toBe("/o/n/issues/7"); | |
| 147 | expect(top("#7")).toBe("/o/n/issues/7"); | |
| 148 | expect(top("repaint fence")).toBe("/o/n/pulls/8"); | |
| 149 | expect(top("#8")).toBe("/o/n/pulls/8"); | |
| 150 | expect(top("pablo")).toBe("/pablo"); | |
| 151 | expect(top("password")).toBe("/settings/password"); | |
| 152 | expect(top("tell crew")).toBe("/o/n/tell"); | |
| 153 | }); |