ostia 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/index.d.ts +62 -35
  2. package/package.json +1 -1
  3. package/src/ab/ab-runner.ts +57 -44
  4. package/src/ab/index.ts +186 -112
  5. package/src/baseline/index.ts +3 -9
  6. package/src/bench/index.ts +177 -123
  7. package/src/bench/projects.ts +14 -10
  8. package/src/bench/registry.ts +68 -66
  9. package/src/bench/run-tasks.ts +26 -23
  10. package/src/bench/run.ts +2 -1
  11. package/src/bench/runner.ts +20 -5
  12. package/src/bench/support.ts +26 -26
  13. package/src/bench/sweep.ts +6 -4
  14. package/src/cache/fingerprint.ts +9 -6
  15. package/src/cache/store.ts +17 -5
  16. package/src/capture/bunflags.ts +12 -11
  17. package/src/capture/cpu-parse.ts +36 -24
  18. package/src/capture/cpu.ts +7 -4
  19. package/src/capture/frames.ts +7 -1
  20. package/src/capture/heap-parse.ts +30 -5
  21. package/src/capture/heap.ts +9 -5
  22. package/src/capture/inspector.ts +8 -7
  23. package/src/capture/jsc-parse.ts +8 -8
  24. package/src/capture/jsc.ts +4 -4
  25. package/src/ci/index.ts +64 -40
  26. package/src/cli/flags.ts +42 -43
  27. package/src/cli/output.ts +29 -35
  28. package/src/cli/run.ts +95 -95
  29. package/src/compare/index.ts +39 -32
  30. package/src/config/env.ts +13 -0
  31. package/src/config/index.ts +31 -23
  32. package/src/config/validate.ts +33 -27
  33. package/src/format.ts +5 -6
  34. package/src/glob.ts +9 -12
  35. package/src/index.ts +1 -3
  36. package/src/ir/cpu.ts +2 -2
  37. package/src/ir/defined.ts +12 -0
  38. package/src/ir/document.ts +93 -73
  39. package/src/ir/fp.ts +7 -10
  40. package/src/ir/git.ts +4 -3
  41. package/src/measure/alloc.ts +7 -8
  42. package/src/measure/cpu.ts +12 -20
  43. package/src/measure/environment.ts +5 -8
  44. package/src/measure/inprocess.ts +15 -15
  45. package/src/measure/instructions.ts +22 -16
  46. package/src/measure/loop.ts +24 -17
  47. package/src/measure/noise.ts +8 -8
  48. package/src/measure/paired.ts +39 -47
  49. package/src/measure/peak.ts +20 -21
  50. package/src/measure/timing.ts +23 -23
  51. package/src/profile.ts +2 -1
  52. package/src/renderers/collapsed.ts +28 -21
  53. package/src/renderers/cpu-tree.ts +43 -35
  54. package/src/renderers/format.ts +16 -26
  55. package/src/renderers/index.ts +14 -4
  56. package/src/renderers/json.ts +2 -2
  57. package/src/renderers/jsonl.ts +11 -7
  58. package/src/renderers/markdown.ts +54 -36
  59. package/src/renderers/mermaid.ts +43 -31
  60. package/src/renderers/minimal.ts +12 -12
  61. package/src/renderers/paired.ts +31 -37
  62. package/src/renderers/relative.ts +10 -14
  63. package/src/renderers/select.ts +17 -39
  64. package/src/renderers/speedscope.ts +52 -48
  65. package/src/renderers/terminal.ts +37 -33
  66. package/src/spawn/index.ts +38 -47
  67. package/src/stats/bootstrap.ts +56 -58
  68. package/src/stats/index.ts +16 -12
  69. package/src/stats/mannwhitney.ts +11 -10
  70. package/src/time.ts +51 -39
@@ -89,43 +89,49 @@ function warningBullets(label: string, warnings: Warning[]): string[] {
89
89
  return warnings.map((w) => `- **${label}**: ${warningNote(w)}`);
90
90
  }
91
91
 
92
- /**
93
- * The two param keys every workload shares, when each has exactly those
94
- * two (a `sweep()` over two dimensions): the shape a pivot table needs. */
92
+ // The two param keys every workload shares, when each has exactly those
93
+ // two (a `sweep()` over two dimensions): the shape a pivot table needs.
95
94
  function pivotKeysFor(
96
95
  workloads: (Workload | undefined)[],
97
96
  ): [string, string] | undefined {
98
- let keys: string[] | undefined;
97
+ let keys: [string, string] | undefined;
99
98
  for (const w of workloads) {
100
- const k = w?.params ? Object.keys(w.params) : undefined;
101
- if (k?.length !== 2) return undefined;
102
- if (keys === undefined) keys = k;
103
- else if (k.some((kk, i) => kk !== keys![i])) return undefined;
99
+ const k = w?.params ? Object.keys(w.params) : [];
100
+ const [first, second] = k;
101
+ if (k.length !== 2 || first === undefined || second === undefined) {
102
+ return undefined;
103
+ }
104
+ if (keys === undefined) keys = [first, second];
105
+ else if (keys[0] !== first || keys[1] !== second) return undefined;
104
106
  }
105
- return keys as [string, string] | undefined;
107
+ return keys;
106
108
  }
107
109
 
108
110
  export const markdownRenderer: Renderer = {
109
111
  name: "markdown",
110
- async render(doc: ProfileDocument): Promise<RenderResult> {
111
- const byWorkload = workloadsById(doc);
112
- const gitSuffix = doc.git ? ` · ${formatGit(doc.git)}` : "";
113
- const mismatch = environmentMismatch(doc);
112
+ render(doc: ProfileDocument): Promise<RenderResult> {
113
+ return Promise.try(() => {
114
+ const byWorkload = workloadsById(doc);
115
+ const gitSuffix = doc.git ? ` · ${formatGit(doc.git)}` : "";
116
+ const mismatch = environmentMismatch(doc);
114
117
 
115
- const lines = [
116
- "# Profile Report",
117
- "",
118
- `Bun ${doc.bunVersion} · ostia ${doc.toolVersion} · ${doc.platform.os}/${doc.platform.arch} · ${doc.createdAt}${gitSuffix}`,
119
- "",
120
- ...(doc.environment ? [formatEnvironmentLine(doc.environment), ""] : []),
121
- ...(mismatch ? [`> ⚠ ${mismatch.message}`, ""] : []),
122
- // Only `ab()` writes paired measurements, and it always stamps `ab`.
123
- ...(doc.ab ? abSection(doc, doc.ab, byWorkload) : []),
124
- ...timingSection(doc, byWorkload),
125
- ...captureSections(doc, byWorkload),
126
- ...comparisonSection(doc),
127
- ];
128
- return { text: lines.join("\n") };
118
+ const lines = [
119
+ "# Profile Report",
120
+ "",
121
+ `Bun ${doc.bunVersion} · ostia ${doc.toolVersion} · ${doc.platform.os}/${doc.platform.arch} · ${doc.createdAt}${gitSuffix}`,
122
+ "",
123
+ ...(doc.environment
124
+ ? [formatEnvironmentLine(doc.environment), ""]
125
+ : []),
126
+ ...(mismatch ? [`> ⚠ ${mismatch.message}`, ""] : []),
127
+ // Only `ab()` writes paired measurements, and it always stamps `ab`.
128
+ ...(doc.ab ? abSection(doc, doc.ab, byWorkload) : []),
129
+ ...timingSection(doc, byWorkload),
130
+ ...captureSections(doc, byWorkload),
131
+ ...comparisonSection(doc),
132
+ ];
133
+ return { text: lines.join("\n") };
134
+ });
129
135
  },
130
136
  };
131
137
 
@@ -190,7 +196,10 @@ function abSection(
190
196
  if (threw.length > 0) {
191
197
  lines.push(`Threw (${threw.length}):`, "");
192
198
  for (const run of threw) {
193
- const message = run.threw.message.split("\n")[0]!.replaceAll("`", "'");
199
+ const message = (run.threw.message.split("\n")[0] ?? "").replaceAll(
200
+ "`",
201
+ "'",
202
+ );
194
203
  lines.push(
195
204
  `- **${taskCell(byWorkload.get(run.workloadId), run.workloadId)}**: ${formatThrew(run.threw)}: \`${message}\``,
196
205
  );
@@ -226,8 +235,6 @@ function timingSection(
226
235
  const runs = timingRuns(doc);
227
236
  const noSamples = noSampleRuns(doc);
228
237
  const memory = memoryReadings(doc);
229
- // Rows with nothing to tabulate: `task.skip()`'d and sample-less
230
- // workloads.
231
238
  const empty: {
232
239
  id: string;
233
240
  workload: Workload | undefined;
@@ -259,8 +266,12 @@ function timingSection(
259
266
  const flat: TimingRow[] = [];
260
267
  for (const row of rows) {
261
268
  const group = groupOf(row.workload);
262
- if (group === undefined) flat.push(row);
263
- else if (byGroup.has(group)) byGroup.get(group)!.push(row);
269
+ if (group === undefined) {
270
+ flat.push(row);
271
+ continue;
272
+ }
273
+ const groupRows = byGroup.get(group);
274
+ if (groupRows) groupRows.push(row);
264
275
  else byGroup.set(group, [row]);
265
276
  }
266
277
  const pivots: { group: string; keys: [string, string]; rows: TimingRow[] }[] =
@@ -302,8 +313,12 @@ function timingSection(
302
313
  if (ratios) {
303
314
  optional.push({
304
315
  header: "Relative",
305
- cell: (row) =>
306
- formatRelative(ratios.get(row)!, !!row.workload?.baseline),
316
+ cell: (row) => {
317
+ const ratio = ratios.get(row);
318
+ return ratio === undefined
319
+ ? "-"
320
+ : formatRelative(ratio, !!row.workload?.baseline);
321
+ },
307
322
  });
308
323
  }
309
324
 
@@ -356,8 +371,11 @@ function timingSection(
356
371
  const colValues: ParamValue[] = [];
357
372
  const medianAt = new Map<string, number>();
358
373
  for (const { run, workload } of groupRows) {
359
- const v1 = workload!.params![key1]!;
360
- const v2 = workload!.params![key2]!;
374
+ const v1 = workload?.params?.[key1];
375
+ const v2 = workload?.params?.[key2];
376
+ // invariant: `pivotKeysFor` pivots only rows whose params hold both
377
+ // keys.
378
+ if (v1 === undefined || v2 === undefined) continue;
361
379
  if (!rowValues.includes(v1)) rowValues.push(v1);
362
380
  if (!colValues.includes(v2)) colValues.push(v2);
363
381
  medianAt.set(`${v1} ${v2}`, run.timing.median);
@@ -17,7 +17,8 @@ function label(name: string, selfUs: number, totalUs: number): string {
17
17
  return `${name.replace(/"/g, "'")} (self ${formatUsAsMs(selfUs)}ms, total ${formatUsAsMs(totalUs)}ms)`;
18
18
  }
19
19
 
20
- // Insertion into a sorted window: O(count * n) with n small.
20
+ // Insertion into a sorted window instead of a full sort, since n is
21
+ // small: O(count * n).
21
22
  function topNBySelf(
22
23
  selfUs: Float64Array,
23
24
  count: number,
@@ -26,12 +27,14 @@ function topNBySelf(
26
27
  ): number[] {
27
28
  const top: number[] = [];
28
29
  if (n <= 0) return top;
30
+ const selfAt = (ix: number | undefined) =>
31
+ ix === undefined ? 0 : (selfUs[ix] ?? 0);
29
32
  for (let i = 0; i < count; i++) {
30
33
  if (i === exclude) continue;
31
- const v = selfUs[i]!;
32
- if (top.length === n && v <= selfUs[top[n - 1]!]!) continue;
34
+ const v = selfAt(i);
35
+ if (top.length === n && v <= selfAt(top[n - 1])) continue;
33
36
  let j = top.length;
34
- while (j > 0 && selfUs[top[j - 1]!]! < v) j--;
37
+ while (j > 0 && selfAt(top[j - 1]) < v) j--;
35
38
  top.splice(j, 0, i);
36
39
  if (top.length > n) top.pop();
37
40
  }
@@ -40,39 +43,48 @@ function topNBySelf(
40
43
 
41
44
  export const mermaidRenderer: Renderer<MermaidOptions> = {
42
45
  name: "mermaid",
43
- async render(
46
+ render(
44
47
  doc: ProfileDocument,
45
48
  options: MermaidOptions = {},
46
49
  ): Promise<RenderResult> {
47
- const topN = options.topN ?? DEFAULT_TOP_N;
50
+ return Promise.try(() => {
51
+ const topN = options.topN ?? DEFAULT_TOP_N;
48
52
 
49
- return renderCpuFiles(doc, options, "mermaid.md", ({ cpu }) => {
50
- const { nodes, frames } = cpu;
51
- const tree = buildDenseTree(cpu);
52
- const { selfUs, totalUs } = computeDenseNodeTimes(cpu, tree);
53
- const { parentIx } = tree;
54
- const rootIx = tree.roots[0] ?? -1;
53
+ return renderCpuFiles(doc, options, "mermaid.md", ({ cpu }) => {
54
+ const { nodes, frames } = cpu;
55
+ const tree = buildDenseTree(cpu);
56
+ const { selfUs, totalUs } = computeDenseNodeTimes(cpu, tree);
57
+ const { parentIx } = tree;
58
+ const rootIx = tree.roots[0] ?? -1;
55
59
 
56
- // The top-N self-time nodes plus every ancestor, so each has a path to the
57
- // root.
58
- const included = new Set<number>(rootIx !== -1 ? [rootIx] : []);
59
- for (const ix of topNBySelf(selfUs, tree.count, rootIx, topN)) {
60
- const path: number[] = [];
61
- for (let cur = ix; cur !== -1; cur = parentIx[cur]!) path.push(cur);
62
- for (let k = path.length - 1; k >= 0; k--) included.add(path[k]!);
63
- }
60
+ // The top-N self-time nodes plus every ancestor, so each has a path to the
61
+ // root.
62
+ const included = new Set<number>(rootIx !== -1 ? [rootIx] : []);
63
+ for (const ix of topNBySelf(selfUs, tree.count, rootIx, topN)) {
64
+ const path: number[] = [];
65
+ for (let cur = ix; cur !== -1; cur = parentIx[cur] ?? -1) {
66
+ path.push(cur);
67
+ }
68
+ for (const p of path.toReversed()) included.add(p);
69
+ }
64
70
 
65
- const id = (ix: number) => `n${nodes[ix]!.id}`;
66
- const lines = ["graph TD"];
67
- for (const ix of included) {
68
- const name = frameName(frames[nodes[ix]!.frameIx]);
69
- lines.push(` ${id(ix)}["${label(name, selfUs[ix]!, totalUs[ix]!)}"]`);
70
- }
71
- for (const ix of included) {
72
- const p = parentIx[ix]!;
73
- if (p !== -1 && included.has(p)) lines.push(` ${id(p)} --> ${id(ix)}`);
74
- }
75
- return `${lines.join("\n")}\n`;
71
+ const id = (ix: number) => `n${nodes[ix]?.id}`;
72
+ const lines = ["graph TD"];
73
+ for (const ix of included) {
74
+ const node = nodes[ix];
75
+ if (node === undefined) continue;
76
+ const name = frameName(frames[node.frameIx]);
77
+ lines.push(
78
+ ` ${id(ix)}["${label(name, selfUs[ix] ?? 0, totalUs[ix] ?? 0)}"]`,
79
+ );
80
+ }
81
+ for (const ix of included) {
82
+ const p = parentIx[ix] ?? -1;
83
+ if (p !== -1 && included.has(p))
84
+ lines.push(` ${id(p)} --> ${id(ix)}`);
85
+ }
86
+ return `${lines.join("\n")}\n`;
87
+ });
76
88
  });
77
89
  },
78
90
  };
@@ -232,6 +232,7 @@ interface MinimalSummaryLine {
232
232
  exitCode: number;
233
233
  }
234
234
 
235
+ /** One parsed line of `--format minimal` output; narrow on `event`. */
235
236
  export type MinimalEvent =
236
237
  MinimalRunLine | MinimalUnmatchedLine | MinimalSummaryLine;
237
238
 
@@ -310,9 +311,6 @@ function deltaFrom(
310
311
  return delta;
311
312
  }
312
313
 
313
- /**
314
- * A `run` line with no stats: a `task.skip()`'d workload, or one whose
315
- * trials produced no samples (`samples: 0`). */
316
314
  function statlessLine(
317
315
  doc: ProfileDocument,
318
316
  workload: Workload,
@@ -428,7 +426,7 @@ function runLines(doc: ProfileDocument): MinimalRunLine[] {
428
426
  line.userNs = sig(times.userNs);
429
427
  line.systemNs = sig(times.systemNs);
430
428
  }
431
- // An `ab` run's stats are the candidate's, memory included.
429
+ // invariant: an `ab` run's stats are the candidate's, memory included.
432
430
  const readings = memory.get(run.workloadId);
433
431
  const retained = readings?.retained ?? run.paired?.retained?.candBytes;
434
432
  if (retained !== undefined) line.retainedBytesPerOp = Math.round(retained);
@@ -587,16 +585,18 @@ function summaryLine(
587
585
 
588
586
  export const minimalRenderer: Renderer<MinimalRenderOptions> = {
589
587
  name: "minimal",
590
- async render(
588
+ render(
591
589
  doc: ProfileDocument,
592
590
  options: MinimalRenderOptions = {},
593
591
  ): Promise<RenderResult> {
594
- const events: MinimalEvent[] = [...runLines(doc)];
595
- if (options.protocol) {
596
- events.push(...unmatchedLines(options.protocol));
597
- events.push(summaryLine(doc, options.protocol));
598
- }
599
- const lines = events.map((l) => JSON.stringify(l));
600
- return { text: lines.length > 0 ? `${lines.join("\n")}\n` : "" };
592
+ return Promise.try(() => {
593
+ const events: MinimalEvent[] = [...runLines(doc)];
594
+ if (options.protocol) {
595
+ events.push(...unmatchedLines(options.protocol));
596
+ events.push(summaryLine(doc, options.protocol));
597
+ }
598
+ const lines = events.map((l) => JSON.stringify(l));
599
+ return { text: lines.length > 0 ? `${lines.join("\n")}\n` : "" };
600
+ });
601
601
  },
602
602
  };
@@ -20,16 +20,16 @@ export type PairedRun = Measurement & {
20
20
  paired: PairedEvidence;
21
21
  };
22
22
 
23
- export type ThrewRun = Measurement & {
23
+ type ThrewRun = Measurement & {
24
24
  threw: NonNullable<Measurement["threw"]>;
25
25
  };
26
26
 
27
- /** A task that threw, on either side, in its first process or a repeat. */
27
+ // Matches a throw on either side, in the first process or a repeat, since
28
+ // both set `threw`.
28
29
  function isThrewRun(m: Measurement): m is ThrewRun {
29
30
  return m.phase === "paired" && m.threw !== undefined;
30
31
  }
31
32
 
32
- /** A task judged on its time: measured, and it never threw. */
33
33
  function isPairedRun(m: Measurement): m is PairedRun {
34
34
  return (
35
35
  m.phase === "paired" &&
@@ -43,15 +43,13 @@ export function pairedRuns(doc: ProfileDocument): PairedRun[] {
43
43
  return doc.measurements.filter(isPairedRun);
44
44
  }
45
45
 
46
- /** An `ab()` document's tasks that threw. */
47
46
  export function threwRuns(doc: ProfileDocument): ThrewRun[] {
48
47
  return doc.measurements.filter(isThrewRun);
49
48
  }
50
49
 
51
- export type AbRow =
50
+ type AbRow =
52
51
  { kind: "timed"; run: PairedRun } | { kind: "threw"; run: ThrewRun };
53
52
 
54
- /** Every row of an A/B table, timed or threw, in document order. */
55
53
  export function abRows(doc: ProfileDocument): AbRow[] {
56
54
  const rows: AbRow[] = [];
57
55
  for (const m of doc.measurements) {
@@ -61,14 +59,10 @@ export function abRows(doc: ProfileDocument): AbRow[] {
61
59
  return rows;
62
60
  }
63
61
 
64
- /**
65
- * `base threw`, `candidate threw`, `both threw`, with `(repeat 1)` when it
66
- * threw in a confirmation repeat. */
67
62
  export function formatThrew(threw: ThrewRun["threw"]): string {
68
63
  return `${sideLabel(threw.side)} threw${threw.repeat ? ` (repeat ${threw.repeat})` : ""}`;
69
64
  }
70
65
 
71
- /** A candidate/base ratio as a signed percent change: `1.032` is `+3.2%`. */
72
66
  function formatRatio(ratio: number): string {
73
67
  return formatSignedPct((ratio - 1) * 100);
74
68
  }
@@ -86,17 +80,26 @@ function pairedVerdict(p: PairedEvidence, metric: AbSummary["metric"]): string {
86
80
  return `${p.confirmed ? `${p.flagged}, confirmed` : `${p.flagged}? unconfirmed`}${repeats}`;
87
81
  }
88
82
 
89
- /** `New suites, not at HEAD: bench/new.bench.ts`, or nothing. */
90
83
  export function formatNewSuites(ab: AbSummary): string | undefined {
91
84
  if (!ab.newSuites?.length) return undefined;
92
85
  return `New suite${ab.newSuites.length > 1 ? "s" : ""}, not at ${ab.base.ref}: ${ab.newSuites.join(", ")}`;
93
86
  }
94
87
 
95
- /**
96
- * The text of one paired row's table cells: `metric`'s per-call medians
97
- * and change, then in `also` the other metric's change (see `alsoHeader`),
98
- * blank on a task without an instruction count. */
99
- export function pairedCells(run: PairedRun, metric: AbSummary["metric"]) {
88
+ interface PairedCells {
89
+ base: string;
90
+ candidate: string;
91
+ change: string;
92
+ spread: string;
93
+ also: string;
94
+ verdict: string;
95
+ }
96
+
97
+ // `also` is the other metric's change (see `alsoHeader`), blank on a task
98
+ // without an instruction count.
99
+ export function pairedCells(
100
+ run: PairedRun,
101
+ metric: AbSummary["metric"],
102
+ ): PairedCells {
100
103
  const p = run.paired;
101
104
  const i = p.instructions;
102
105
  const judged = metricRatios(p, metric);
@@ -123,9 +126,6 @@ export function pairedCells(run: PairedRun, metric: AbSummary["metric"]) {
123
126
  };
124
127
  }
125
128
 
126
- /**
127
- * The header of `pairedCells`'s `also` column, or undefined when no row
128
- * would fill it. */
129
129
  export function alsoHeader(
130
130
  doc: ProfileDocument,
131
131
  metric: AbSummary["metric"],
@@ -136,13 +136,12 @@ export function alsoHeader(
136
136
  : undefined;
137
137
  }
138
138
 
139
- export interface MemoryRow {
139
+ interface MemoryRow {
140
140
  run: PairedRun;
141
141
  reading: "retained/op" | "peak";
142
142
  change: MemoryChange;
143
143
  }
144
144
 
145
- /** Each timed task's memory readings, retained before peak. */
146
145
  export function memoryRows(doc: ProfileDocument): MemoryRow[] {
147
146
  return pairedRuns(doc).flatMap((run) => {
148
147
  const rows: MemoryRow[] = [];
@@ -153,9 +152,8 @@ export function memoryRows(doc: ProfileDocument): MemoryRow[] {
153
152
  });
154
153
  }
155
154
 
156
- /**
157
- * `+1.50MiB (+87.4%)`, in whole bytes; no percent when the base is under
158
- * the noise floor, where it would be huge and meaningless. */
155
+ // No percent when the base is under the noise floor, where it would be
156
+ // huge and meaningless.
159
157
  function formatByteChange(c: MemoryChange): string {
160
158
  const base = Math.round(c.baseBytes);
161
159
  const diff = Math.round(c.candBytes) - base;
@@ -165,8 +163,15 @@ function formatByteChange(c: MemoryChange): string {
165
163
  return `${bytes} (${formatSignedPct((diff / base) * 100)})`;
166
164
  }
167
165
 
168
- /** The text of one memory row's table cells. */
169
- export function memoryCells({ reading, change: c }: MemoryRow) {
166
+ interface MemoryCells {
167
+ reading: MemoryRow["reading"];
168
+ base: string;
169
+ candidate: string;
170
+ change: string;
171
+ verdict: string;
172
+ }
173
+
174
+ export function memoryCells({ reading, change: c }: MemoryRow): MemoryCells {
170
175
  return {
171
176
  reading,
172
177
  base: formatBytes(c.baseBytes),
@@ -176,10 +181,6 @@ export function memoryCells({ reading, change: c }: MemoryRow) {
176
181
  };
177
182
  }
178
183
 
179
- /**
180
- * `working tree vs HEAD (26e7d0d) · 15 rounds · threshold 10% · geomean
181
- * threshold 1.5%`, with `· by instructions/call` after the rounds when
182
- * that's the metric. */
183
184
  export function formatAbHeader(ab: AbSummary): string {
184
185
  const metric = ab.metric === "instructions" ? " · by instructions/call" : "";
185
186
  const memory = ab.memory
@@ -188,10 +189,6 @@ export function formatAbHeader(ab: AbSummary): string {
188
189
  return `working tree vs ${ab.base.ref} (${ab.base.sha.slice(0, 7)}) · ${ab.rounds} rounds${metric} · threshold ${ab.thresholdPct}% · geomean threshold ${ab.geomeanThresholdPct}%${memory}`;
189
190
  }
190
191
 
191
- /**
192
- * `Geomean +2.1% (threshold 1.5%) · 1 regressed, 0 improved, 47 unchanged
193
- * of 48 (1 unconfirmed) · memory: 0 regressed, 1 improved · fail`
194
- */
195
192
  export function formatAbSummary(ab: AbSummary): string {
196
193
  const geomean =
197
194
  ab.geomeanPct === null
@@ -209,9 +206,6 @@ export function formatAbSummary(ab: AbSummary): string {
209
206
  return `${geomean} · ${ab.regressed} regressed, ${ab.improved} improved, ${ab.unchanged} unchanged of ${ab.matched}${unconfirmed}${memory} · ${ab.verdict}`;
210
207
  }
211
208
 
212
- /**
213
- * Labels of workloads whose output differed between sides, and of those
214
- * present on only one side. */
215
209
  export function abNotes(doc: ProfileDocument): {
216
210
  outputDiffers: string[];
217
211
  baseOnly: string[];
@@ -6,10 +6,9 @@ export interface TimingRow {
6
6
  workload: Workload | undefined;
7
7
  }
8
8
 
9
- /**
10
- * The explicit `entry.group` the bench runner records, else the
11
- * "group/name" id split on its last "/" (documents from before that field
12
- * existed). */
9
+ // The explicit `entry.group` the bench runner records, else the
10
+ // "group/name" id split on its last "/" (documents from before that field
11
+ // existed).
13
12
  export function groupOf(workload: Workload | undefined): string | undefined {
14
13
  if (!workload?.entry) return undefined;
15
14
  if (workload.entry.group !== undefined) return workload.entry.group;
@@ -18,21 +17,18 @@ export function groupOf(workload: Workload | undefined): string | undefined {
18
17
  return idx === -1 ? undefined : id.slice(0, idx);
19
18
  }
20
19
 
21
- /**
22
- * A row's label under its group's header: the task name alone, since the
23
- * header already shows the group. */
20
+ // The task name alone, since the group's header already shows the group.
24
21
  export function labelInGroup(label: string, group: string | undefined): string {
25
22
  return group !== undefined && label.startsWith(`${group}/`)
26
23
  ? label.slice(group.length + 1)
27
24
  : label;
28
25
  }
29
26
 
30
- /**
31
- * Each row's median over its reference median: its group's
32
- * `task(..., { baseline: true })` task, else the group's fastest.
33
- * Ungrouped rows use the fastest in the document; tasks never compare
34
- * across groups. Undefined with fewer than two rows, where "relative"
35
- * means nothing. */
27
+ // Each row's reference median is its group's
28
+ // `task(..., { baseline: true })` task, else the group's fastest.
29
+ // Ungrouped rows use the fastest in the document; tasks never compare
30
+ // across groups. Undefined with fewer than two rows, where "relative"
31
+ // means nothing.
36
32
  export function relativeRatios<R extends TimingRow>(
37
33
  rows: R[],
38
34
  ): Map<R, number> | undefined {
@@ -52,7 +48,7 @@ export function relativeRatios<R extends TimingRow>(
52
48
  const key = groupOf(row.workload);
53
49
  let reference = fastestMedian;
54
50
  if (key !== undefined) {
55
- const siblings = siblingsByGroup.get(key)!;
51
+ const siblings = siblingsByGroup.get(key) ?? [row];
56
52
  const baselineRow = siblings.find((s) => s.workload?.baseline);
57
53
  reference = baselineRow
58
54
  ? baselineRow.run.timing.median
@@ -14,15 +14,16 @@ import {
14
14
  workloadLabel,
15
15
  } from "./format.ts";
16
16
 
17
- // Below this absolute percent a frame/heap-type delta is noise, not a row.
17
+ // Below this absolute percent a frame/heap-type delta is noise, so it gets
18
+ // no row.
18
19
  const MIN_DISPLAY_DELTA_PCT = 0.5;
19
20
 
20
21
  export type TimingRun = Measurement & {
21
22
  timing: NonNullable<Measurement["timing"]>;
22
23
  };
23
24
 
24
- export type FrameDelta = NonNullable<Comparison["frames"]>[number];
25
- export type HeapTypeDelta = NonNullable<Comparison["heapTypes"]>[number];
25
+ type FrameDelta = NonNullable<Comparison["frames"]>[number];
26
+ type HeapTypeDelta = NonNullable<Comparison["heapTypes"]>[number];
26
27
 
27
28
  export function workloadsById(doc: ProfileDocument): Map<string, Workload> {
28
29
  return new Map(doc.workloads.map((w) => [w.id, w]));
@@ -34,20 +35,14 @@ export function timingRuns(doc: ProfileDocument): TimingRun[] {
34
35
  );
35
36
  }
36
37
 
37
- /**
38
- * Timing measurements that produced no samples (every trial timed out or
39
- * missed the `timeSource` pattern). Renderers show them as "no samples"
40
- * rows so their warnings stay visible. */
38
+ // Every trial timed out or missed the `timeSource` pattern. Renderers show
39
+ // these as "no samples" rows so their warnings stay visible.
41
40
  export function noSampleRuns(doc: ProfileDocument): Measurement[] {
42
41
  return doc.measurements.filter(
43
42
  (r) => r.phase === "timing" && r.timing === undefined,
44
43
  );
45
44
  }
46
45
 
47
- /**
48
- * `task.skip()`'d workloads with no measurement, rendered as "- skipped"
49
- * rows.
50
- */
51
46
  export function skippedWorkloads(
52
47
  doc: ProfileDocument,
53
48
  runs: { workloadId: string }[],
@@ -56,10 +51,9 @@ export function skippedWorkloads(
56
51
  return doc.workloads.filter((w) => w.skipped && !measured.has(w.id));
57
52
  }
58
53
 
59
- /**
60
- * `environment-mismatch` is the same on every comparison (it concerns the
61
- * base/cand pair): renderers print it once, from here, and drop it per
62
- * row. */
54
+ // `environment-mismatch` is the same on every comparison because it
55
+ // concerns the base/cand pair, so renderers print it once, from here, and
56
+ // drop it per row.
63
57
  export function environmentMismatch(doc: ProfileDocument): Warning | undefined {
64
58
  for (const c of doc.comparisons ?? []) {
65
59
  const w = c.warnings?.find((w) => w.code === "environment-mismatch");
@@ -72,11 +66,9 @@ export function rowComparisonWarnings(cmp: Comparison): Warning[] {
72
66
  return (cmp.warnings ?? []).filter((w) => w.code !== "environment-mismatch");
73
67
  }
74
68
 
75
- /**
76
- * Resolves a comparison to its candidate measurement and workload, plus
77
- * the workload id (the display fallback when the document lacks the
78
- * workload). A skipped candidate has no measurement, so
79
- * `candidateMeasurementId` then holds the workload id itself. */
69
+ // The workload id is the display fallback when the document lacks the
70
+ // workload. A skipped candidate has no measurement, so
71
+ // `candidateMeasurementId` then holds the workload id itself.
80
72
  function comparisonResolver(doc: ProfileDocument) {
81
73
  const workloads = workloadsById(doc);
82
74
  const runs = new Map(doc.measurements.map((m) => [m.id, m]));
@@ -102,7 +94,7 @@ export function shownHeapDeltas(
102
94
  .filter((h) => Math.abs(h.deltaPct) >= MIN_DISPLAY_DELTA_PCT);
103
95
  }
104
96
 
105
- export interface MemoryReadings {
97
+ interface MemoryReadings {
106
98
  /** `--alloc`: heap each call retains, bytes. */
107
99
  retained?: number;
108
100
  /** `--peak-mem`: RSS rise of one call, bytes. */
@@ -127,7 +119,6 @@ export function memoryReadings(
127
119
  return byWorkload;
128
120
  }
129
121
 
130
- /** A timing run's warnings plus its workload's `memstats` warnings. */
131
122
  export function runWarnings(
132
123
  run: Measurement,
133
124
  memory: Map<string, MemoryReadings>,
@@ -136,16 +127,12 @@ export function runWarnings(
136
127
  return extra?.length ? [...run.warnings, ...extra] : run.warnings;
137
128
  }
138
129
 
139
- export interface MemoryColumn {
130
+ interface MemoryColumn {
140
131
  header: string;
141
132
  /** Formatted bytes, or undefined when this workload has no reading. */
142
133
  cell: (workloadId: string) => string | undefined;
143
134
  }
144
135
 
145
- /**
146
- * `Retained/op` and `Peak mem` columns, each only when some workload has
147
- * it.
148
- */
149
136
  export function memoryColumns(
150
137
  memory: Map<string, MemoryReadings>,
151
138
  ): MemoryColumn[] {
@@ -168,11 +155,9 @@ export function memoryColumns(
168
155
  }));
169
156
  }
170
157
 
171
- /**
172
- * The document's `compared` rows, each with its `Comparison` (absent on a
173
- * one-sided task). A document compared before `compared` existed gets rows
174
- * rebuilt from `comparisons` and `unmatched`: no sample counts or memory,
175
- * the base median derived from the change, base-only tasks named by id. */
158
+ // A document compared before `compared` existed gets rows rebuilt from
159
+ // `comparisons` and `unmatched`: no sample counts or memory, the base
160
+ // median derived from the change, base-only tasks named by id.
176
161
  export function comparedRows(
177
162
  doc: ProfileDocument,
178
163
  ): { row: ComparedTask; cmp: Comparison | undefined }[] {
@@ -251,9 +236,6 @@ const MEMORY_READING_LABELS: Record<MemoryDelta["reading"], string> = {
251
236
  maxRss: "max RSS",
252
237
  };
253
238
 
254
- /**
255
- * `heap used before 12.00MiB → 16.80MiB (+40.0%)` for each memory reading
256
- * that moved at least 10%. */
257
239
  export function shownMemoryDeltas(row: ComparedTask, arrow = "→"): string[] {
258
240
  return (row.memory ?? [])
259
241
  .filter((m) => !(Math.abs(m.deltaPct) < MIN_MEMORY_DISPLAY_PCT))
@@ -263,9 +245,6 @@ export function shownMemoryDeltas(row: ComparedTask, arrow = "→"): string[] {
263
245
  );
264
246
  }
265
247
 
266
- /**
267
- * `Timing threshold 5.0%, widened to 17.3% by machine noise and drift
268
- * (12.3%)`, when noise or drift widened it; else undefined. */
269
248
  export function thresholdNote(doc: ProfileDocument): string | undefined {
270
249
  const summary = doc.comparisonSummary;
271
250
  const base = doc.comparisons?.[0]?.thresholds.timingPct;
@@ -278,7 +257,6 @@ export function thresholdNote(doc: ProfileDocument): string | undefined {
278
257
  return `Timing threshold ${base.toFixed(1)}%, widened to ${summary.effectiveTimingPct.toFixed(1)}% by machine noise${drift}`;
279
258
  }
280
259
 
281
- /** "base only" / "candidate only", and what that usually means. */
282
260
  export function oneSidedNote(verdict: "missing-base" | "missing-cand"): string {
283
261
  return verdict === "missing-base"
284
262
  ? "candidate only (new, or renamed without `aliases`)"