perf(report): avoid copying accumulated Markdown file results

JX
3h ago
+8-1

What and why

  • fileGroups in packages/e2e/src/report/markdown.ts copied every earlier entry of a target/file group each time it added one, so a group of n results did O(n²) copying. Each group now owns one array that results are pushed into.
  • The comparator, result order, 400-row display cap, 60,000-character limit and rendered bytes are unchanged. No public API, schema or option changed. The changeset is a patch line, as the triage comment on #1802 asked for when output is identical.
const grouped = byFile.get(entry.result.file);
if (grouped) grouped.push(entry);
else byFile.set(entry.result.file, [entry]);
  • No tests are added: packages/e2e/tests/unit/report-markdown.test.ts is unchanged from main.

Issue

Fixes #1802

Verified

Ran it locally: yes

  • Built renderMarkdownReport from main b56e8ed5 and from this change, then compared output for ten schema-valid workloads: identical bytes. An independent reviewer checked another 49 frozen cases, including stored CLI reports, truncation and shared references, with identical output and unchanged inputs. Since b56e8ed5, main has changed only import paths in these two files; the grouping hunks apply with zero fuzz.
  • Ran both built CLIs with the repository's synthetic engine on two targets with --repeat-each 2. Both wrote schema-valid reports and summaries with 14 selected, 12 executed, 8 passed, 4 planted failures and 2 skipped, and both exited 1 because of the planted failures. No browser or model was used.
  • Both checks above ran on the earlier let/if form of the loop, before this revision. The shorter form does the same work, because a bucket is never empty once it exists.

Elapsed milliseconds per full render of the built renderer, from that b56e8ed5 comparison (Node 24.22.2, Apple M3 Pro, eight warmups, nine alternating paired samples, medians):

Workloadmainthis change
100 results, one file0.3110.309
1,000 results, one file2.8312.281
10,000 results, one file57.07821.394
1,000 results, 100 files2.3122.305
10,000 results, 100 files21.77722.042

These numbers are renderer time only. Dense one-file groups improve; small and spread-out reports show no consistent difference. They say nothing about suite, CI or memory.

pnpm bench:ab was not run. It invokes e2e run --reporter json (scripts/bench-ab.ts:187), replacing the built-in Markdown reporter, and strips GITHUB_* (scripts/bench-ab.ts:152), so the configured GitHub reporter also returns before rendering. It does not exercise the Markdown renderer.

This revision on Node 24.22.2 (local commit 0d710d2f): the Markdown and reporter tests (report-markdown.test.ts, reporters.test.ts and the GitHub reporter.test.ts), pnpm build and pnpm check passed. The first full pnpm test ran at a load average of 26 to 30 and failed 5 tests in mcp-test-run.test.ts and screenshot-assertions.test.ts. Run alone, screenshot-assertions passed, while mcp-test-run failed first on a tap that timed out after 235 ms, then on a session-slot cascade. The second full run, at a load of about 5, passed every e2e test but failed 27 web CDP and download tests, because the Playwright Chromium binary was missing until partway through that run. With the browser confirmed present, the four affected web files passed (32 tests), and one more full pnpm test exited 0: e2e 4,673 passed, 11 skipped; web 832 passed, 1 skipped; every later package and test:scripts passed.