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

The impact map formats 3,100 tests without the default sort: 4.3 s to 0.6 s #12558

Merged opened this

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

Merged

mason/forge:mason/12555-the-impact-map-formats-3-100-tests-witho → main 3 commits fork 2 threads · 2 unresolved

  • Merged. mason/12555-the-impact-map-formats-3-100-tests-witho was merged into main as 740aa94.

Review

Sign in to review this change.
2 files changed +44 −3
src/checks/impact.ts +14 −3
@@ -187,11 +187,22 @@ export function parseImpact(
187187 return { ok: true, value: map };
188188 }
189189
190 const byCodeUnit = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);
191
192 /**
193 * Sorted by code unit (what a bare `.sort()` gives, without its string
194 * conversions); a list already in order is returned as is.
195 */
196 function sortedNames(list: readonly string[]): readonly string[] {
197 for (let i = 1; i < list.length; i++) if (list[i - 1]! > list[i]!) return [...list].sort(byCodeUnit);
198 return list;
outdated

list as string[] drops readonly; return readonly string[] instead. Add a test for the already-sorted and unsorted paths.

199 }
200
190201 export function formatImpact(map: ReadonlyMap<string, readonly string[]>): string {
191 const entries = [...map].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
202 const entries = [...map].sort(([a], [b]) => byCodeUnit(a, b));

Needs a test comparing output with the bare .sort() reference, including non-ASCII names, so the byte-for-byte claim is checked and not assumed.

192203 if (entries.length === 0) return "{}\n";
193204 const lines = entries.map(
194 ([test, files]) => ` ${JSON.stringify(test)}: ${JSON.stringify([...files].sort())}`,
205 ([test, files]) => ` ${JSON.stringify(test)}: ${JSON.stringify(sortedNames(files))}`,
195206 );
196207 return `{\n${lines.join(",\n")}\n}\n`;
197208 }
@@ -216,7 +227,7 @@ const packedName = (test: string): string => test.replace(/^test\//, "test/.");
216227 * unchanged; it finds no test's own name in it, and reads it as no map.
217228 */
218229 export function packImpact(map: Impact): Map<string, string[]> {
219 const files = [...new Set([...map.values()].flat())].sort();
230 const files = [...new Set([...map.values()].flat())].sort(byCodeUnit);
220231 const place = new Map(files.map((file, i) => [file, i]));
221232 const packed = new Map<string, string[]>([[PACK_FILES, files]]);
222233 for (const [test, entry] of map) {
test/check-tiers.test.ts +30
@@ -377,6 +377,36 @@ describe("the packed impact map (#12178)", () => {
377377 expect(unpackImpact(parsed.value)).toEqual(wide);
378378 });
379379
380 test("the map is ordered as the default sort orders it: unsorted, sorted, empty, single, non-ASCII", () => {
381 const astral = "src/\u{1F600}.ts";
382 const lists = [
383 [],
384 ["src/a.ts"],
385 ["src/a.ts", "src/b.ts", "src/c.ts"],
386 ["src/z.ts", "src/\u00e9.ts", "src/a.ts", "src/B.ts"],
387 [astral, "src/\uffff.ts", "src/\ue000.ts", "src/a.ts"],
388 ["src/b.ts", "src/b.ts", "src/a.ts"],
389 ];
390 const tests = ["test/\u00e9.test.ts", "test/z.test.ts", `test/${"\u{1F600}"}.test.ts`, "test/\uffff.test.ts", "test/a.test.ts"];
391 for (const forward of [true, false]) {
392 const map = new Map<string, string[]>();
393 (forward ? tests : [...tests].reverse()).forEach((t, i) => map.set(t, [...lists[i % lists.length]!]));
394 const bare = [...map.keys()].sort();
395 const expected = `{\n${bare
396 .map((t) => ` ${JSON.stringify(t)}: ${JSON.stringify([...map.get(t)!].sort())}`)
397 .join(",\n")}\n}\n`;
398 expect(formatImpact(map)).toBe(expected);
399 const packed = packImpact(map);
400 expect(packed.get(PACK_FILES)).toEqual([...new Set([...map.values()].flat())].sort());
401 const unpacked = unpackImpact(packed)!;
402 for (const t of bare) expect(unpacked.get(t)).toEqual([...new Set(map.get(t)!)].sort());
403 }
404 expect(formatImpact(new Map())).toBe("{}\n");
405 const input = ["src/b.ts", "src/a.ts"];
406 formatImpact(new Map([["test/x.test.ts", input]]));
407 expect(input).toEqual(["src/b.ts", "src/a.ts"]);
408 });
409
380410 test("packed, three thousand tests of five hundred files each stay far under what the forge keeps", () => {
381411 const files = Array.from({ length: 3300 }, (_, i) => `src/some/longer/directory/file-${i}.ts`);
382412 const big = new Map(

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs