ostia 0.4.0 → 0.5.0

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 (59) hide show
  1. package/README.md +4 -4
  2. package/docs/agent-protocol.md +13 -9
  3. package/docs/cli.md +90 -73
  4. package/docs/config.md +2 -2
  5. package/docs/document-schema.md +14 -12
  6. package/docs/library.md +17 -15
  7. package/docs/preload-recipes.md +4 -4
  8. package/docs/statistics.md +10 -10
  9. package/index.d.ts +128 -58
  10. package/package.json +1 -1
  11. package/src/ab/ab-runner.ts +6 -6
  12. package/src/ab/index.ts +15 -6
  13. package/src/bench/index.ts +12 -3
  14. package/src/bench/registry.ts +6 -4
  15. package/src/bench/run-tasks.ts +2 -2
  16. package/src/bench/runner.ts +2 -2
  17. package/src/bench/support.ts +8 -4
  18. package/src/bench/sweep.ts +2 -2
  19. package/src/cache/fingerprint.ts +2 -2
  20. package/src/capture/bunflags.ts +2 -2
  21. package/src/capture/cpu.ts +2 -2
  22. package/src/capture/heap-parse.ts +2 -2
  23. package/src/ci/index.ts +7 -6
  24. package/src/cli/agent.ts +54 -0
  25. package/src/cli/flags.ts +50 -9
  26. package/src/cli/help.ts +29 -11
  27. package/src/cli/output.ts +6 -3
  28. package/src/cli/run.ts +29 -5
  29. package/src/compare/index.ts +4 -4
  30. package/src/config/index.ts +14 -10
  31. package/src/config/validate.ts +4 -4
  32. package/src/glob.ts +2 -2
  33. package/src/ir/document.ts +2 -2
  34. package/src/ir/types.ts +47 -24
  35. package/src/measure/alloc.ts +2 -2
  36. package/src/measure/cpu.ts +2 -2
  37. package/src/measure/environment.ts +11 -6
  38. package/src/measure/inprocess.ts +14 -10
  39. package/src/measure/instructions.ts +2 -2
  40. package/src/measure/noise.ts +51 -13
  41. package/src/measure/paired.ts +2 -2
  42. package/src/measure/peak.ts +4 -4
  43. package/src/measure/timing.ts +18 -3
  44. package/src/profile.ts +6 -4
  45. package/src/renderers/collapsed.ts +2 -2
  46. package/src/renderers/concise.ts +148 -0
  47. package/src/renderers/format.ts +13 -4
  48. package/src/renderers/index.ts +6 -0
  49. package/src/renderers/markdown.ts +2 -2
  50. package/src/renderers/mermaid.ts +2 -2
  51. package/src/renderers/minimal.ts +8 -7
  52. package/src/renderers/relative.ts +2 -2
  53. package/src/renderers/select.ts +2 -2
  54. package/src/renderers/terminal.ts +6 -3
  55. package/src/renderers/types.ts +3 -0
  56. package/src/spawn/index.ts +47 -14
  57. package/src/stats/bootstrap.ts +2 -2
  58. package/src/stats/index.ts +2 -2
  59. package/src/time.ts +75 -10
@@ -1,7 +1,7 @@
1
1
  # Statistics
2
2
 
3
- How ostia samples, summarizes, and decides whether a change is a
4
- regression.
3
+ How ostia samples, summarizes, and decides whether a change is
4
+ a regression.
5
5
 
6
6
  ## Summary statistics
7
7
 
@@ -58,8 +58,8 @@ For the most comparable numbers, run tasks with `isolate`.
58
58
 
59
59
  Before measuring, `time()`, `bench()` and `ostia ci` each run a fixed,
60
60
  allocation-free hash loop for about 200ms, once per call,
61
- and record `mad / median` of its trial times as
62
- `environment.noise.floorPct`.
61
+ and record `mad / median` of its trial times
62
+ as `environment.noise.floorPct`.
63
63
  This is how much this machine's timings vary at the moment,
64
64
  independent of the workload.
65
65
  `noiseCheck: false` / `--no-noise-check` skips it
@@ -89,8 +89,8 @@ each side, runs two tests on the raw samples:
89
89
  first, which bounds the cost.
90
90
  - **Mann-Whitney U test**, two-sided, tie-corrected,
91
91
  normal approximation, reported as `pValue`.
92
- It tests whether the two distributions differ without assuming
93
- normality.
92
+ It tests whether the two distributions differ without
93
+ assuming normality.
94
94
 
95
95
  The bootstrap PRNG is seeded from a hash of the two sample arrays,
96
96
  so the same two documents always produce the same interval and verdict.
@@ -108,8 +108,8 @@ Let `T = effectiveTimingPct` (below).
108
108
  A large point estimate is not enough.
109
109
  For example, `+21.4% median, 95% CI [+5.6%, +23.9%], p=0.023` against
110
110
  `T = 10` and `alpha = 0.01` is `unchanged`:
111
- the interval reaches below the threshold and the p-value is above
112
- `alpha`.
111
+ the interval reaches below the threshold
112
+ and the p-value is above `alpha`.
113
113
 
114
114
  With fewer than 5 samples on either side,
115
115
  the tests are skipped and the verdict uses the median change alone
@@ -214,5 +214,5 @@ which is why the quartile rule and confirmation stay.
214
214
  When base and candidate differ in OS, architecture, Bun version,
215
215
  or (when both have it) CPU model or core count,
216
216
  every comparison carries an `environment-mismatch` warning with the
217
- differing fields: the delta may reflect the machine rather than the
218
- code.
217
+ differing fields: the delta may reflect the machine rather than
218
+ the code.
package/index.d.ts CHANGED
@@ -31,15 +31,19 @@ export interface AbOptions {
31
31
  outDir?: string;
32
32
  cwd?: string;
33
33
  noiseCheck?: boolean;
34
+ /** Sample the noise floor for exactly this many ms instead. */
35
+ noiseBudgetMs?: number;
34
36
  /** Also compare each side's retained heap per call (see
35
37
  * `bench({ alloc })`) and how far its first call raises RSS (see
36
38
  * `bench({ peakMem })`), each the median of 3 fresh processes per side.
37
39
  * Task/group options override these. */
38
40
  alloc?: boolean;
39
41
  peakMem?: boolean;
40
- /** Flag a memory reading that moves past this many percent of the base's
41
- * and past its noise floor (default: 10). A memory regression fails the
42
- * run. */
42
+ /**
43
+ * Flag a memory reading that moves past this many percent of the base's
44
+ * and past its noise floor (default: 10). A memory regression fails
45
+ * the run.
46
+ */
43
47
  memThresholdPct?: number;
44
48
  /** Shell commands run once, in order, in a freshly extracted base tree
45
49
  * before it's used: to build what the suites import but git doesn't hold
@@ -64,8 +68,9 @@ export interface AbOptions {
64
68
  onProgress?: (progress: AbProgress) => void;
65
69
  }
66
70
  /**
67
- * Launch settings for the suite files matching `suites`; see
68
- * `BenchOptions.projects`. */
71
+ * Launch settings for the suite files matching `suites`;
72
+ * see `BenchOptions.projects`.
73
+ */
69
74
  export interface BenchProject {
70
75
  /**
71
76
  * Globs against the current directory. A suite file takes the first
@@ -143,17 +148,28 @@ export interface ProfileDocument {
143
148
  * `comparisons` is. */
144
149
  compared?: ComparedTask[];
145
150
  /**
146
- * Machine conditions at measurement time; absent when the noise check was
147
- * skipped. */
151
+ * Machine conditions at measurement time; absent when the noise check
152
+ * was skipped.
153
+ */
148
154
  environment?: Environment;
149
155
  /**
150
- * Run-level result of `ostia ab` / `ab()`, whose measurements are
151
- * `phase: "paired"`. */
156
+ * The shell `time({ shell })` ran each string command through, and its
157
+ * startup (`shell -c :`, median wall time, ns), which the timings include
158
+ * and nothing subtracts. Absent without a shell. */
159
+ shell?: {
160
+ command: string;
161
+ startupNs: number;
162
+ };
163
+ /**
164
+ * Run-level result of `ostia ab` / `ab()`, whose measurements
165
+ * are `phase: "paired"`.
166
+ */
152
167
  ab?: AbSummary;
153
168
  /**
154
169
  * Repo state of the process's cwd; absent outside a git repo. Never part
155
- * of an id or fingerprint, so a commit or dirty tree doesn't orphan a
156
- * baseline. */
170
+ * of an id or fingerprint, so a commit or dirty tree doesn't orphan
171
+ * a baseline.
172
+ */
157
173
  git?: GitMetadata;
158
174
  }
159
175
  export interface Workload {
@@ -253,6 +269,8 @@ type Phase = "timing" | "cpu" | "heap" | "memstats" | "paired";
253
269
  interface Trial {
254
270
  i: number;
255
271
  wallNs: number;
272
+ /** The file `--save-output` wrote this trial's stdout and stderr to. */
273
+ outputPath?: string;
256
274
  /**
257
275
  * The command's self-reported time (ns) under a `timeSource`; these, not
258
276
  * `wallNs`, are then the `timing.samples`. */
@@ -338,8 +356,9 @@ interface MemoryEvidence {
338
356
  origin: "resourceUsage" | "heapStats";
339
357
  /**
340
358
  * `memstats` only: `"retained"` (`--alloc`, `bytesPerOp`) or `"peak"`
341
- * (`--peak-mem`, `peakBytes`). Absent means `"retained"` on older
342
- * documents. */
359
+ * (`--peak-mem`, `peakBytes`). Absent means `"retained"` on
360
+ * older documents.
361
+ */
343
362
  kind?: "retained" | "peak";
344
363
  /** Largest `Trial.maxRssBytes` across a timing measurement's trials. */
345
364
  maxRssBytes?: number;
@@ -410,8 +429,9 @@ export interface PairedEvidence {
410
429
  * side of 1 in at least three quarters of rounds. */
411
430
  flagged?: "regressed" | "improved";
412
431
  /**
413
- * Each fresh-process re-measurement of a flagged workload; `flagged` by
414
- * `AbSummary.metric`. */
432
+ * Each fresh-process re-measurement of a flagged workload; `flagged`
433
+ * by `AbSummary.metric`.
434
+ */
415
435
  repeats?: {
416
436
  medianRatio: number;
417
437
  ratioP25: number;
@@ -482,8 +502,8 @@ export interface Warning {
482
502
  }
483
503
  export type WarningCode = (typeof WARNING_CODES)[number];
484
504
  /**
485
- * Every `Warning.code`. A runtime array so a test can assert each is
486
- * emitted.
505
+ * Every `Warning.code`. A runtime array so a test can assert each
506
+ * is emitted.
487
507
  */
488
508
  export declare const WARNING_CODES: readonly [
489
509
  "slow-first-run",
@@ -529,8 +549,8 @@ export interface Comparison {
529
549
  verdict: "improved" | "regressed" | "unchanged";
530
550
  };
531
551
  /**
532
- * Caveats about this comparison, e.g. a thin-sample point-estimate
533
- * verdict.
552
+ * Caveats about this comparison, e.g. a thin-sample
553
+ * point-estimate verdict.
534
554
  */
535
555
  warnings?: Warning[];
536
556
  frames?: {
@@ -556,8 +576,8 @@ export interface Comparison {
556
576
  alpha: number;
557
577
  bootstrapIterations: number;
558
578
  /**
559
- * `max(timingPct, both documents' noise floors)`: what timing was tested
560
- * against.
579
+ * `max(timingPct, both documents' noise floors)`: what timing was
580
+ * tested against.
561
581
  */
562
582
  effectiveTimingPct: number;
563
583
  };
@@ -635,8 +655,9 @@ export interface ComparedTask {
635
655
  interface MemoryDelta {
636
656
  /**
637
657
  * `heapUsedBefore`/`heapUsedAfter`: in-process heap around the timing
638
- * run; `retained`: `--alloc`; `peak`: `--peak-mem`; `maxRss`: subprocess
639
- * timing. */
658
+ * run; `retained`: `--alloc`; `peak`: `--peak-mem`; `maxRss`:
659
+ * subprocess timing.
660
+ */
640
661
  reading: "heapUsedBefore" | "heapUsedAfter" | "retained" | "peak" | "maxRss";
641
662
  baseBytes: number;
642
663
  candBytes: number;
@@ -656,6 +677,14 @@ interface NoiseFloor {
656
677
  floorPct: number;
657
678
  referenceMedianNs: number;
658
679
  samples: number;
680
+ /**
681
+ * How long the check sampled, in milliseconds: 25 to 50 by default, as
682
+ * long as the median took to hold. Absent in older documents. */
683
+ checkMs?: number;
684
+ /**
685
+ * The fixed budget `--noise-budget` asked for, in milliseconds; absent
686
+ * for the default, adaptive check. */
687
+ budgetMs?: number;
659
688
  /**
660
689
  * How much slower (positive) the reference ran at the end of the run than
661
690
  * at the start, percent: the machine's drift over the run. Absent when the
@@ -686,15 +715,17 @@ export interface AbSummary {
686
715
  improved: number;
687
716
  unchanged: number;
688
717
  /**
689
- * Flagged in-process, but a fresh-process repeat disagreed; counted in
690
- * `unchanged`. */
718
+ * Flagged in-process, but a fresh-process repeat disagreed; counted
719
+ * in `unchanged`.
720
+ */
691
721
  unconfirmed: number;
692
722
  /** Workloads whose first call returned different values on each side. */
693
723
  outputDiffers: number;
694
724
  /**
695
725
  * Workloads whose suite file and output both changed (see
696
- * `PairedEvidence.suiteChanged`); counted in `unchanged`, left out of
697
- * `geomeanPct`. */
726
+ * `PairedEvidence.suiteChanged`); counted in `unchanged`, left out
727
+ * of `geomeanPct`.
728
+ */
698
729
  notComparable: number;
699
730
  /**
700
731
  * Workloads that threw on either side or both, and so weren't timed;
@@ -806,6 +837,8 @@ export interface BenchOptions {
806
837
  * Measure this machine's noise floor once, before any suite runs
807
838
  * (default: true), and stamp it on the document as `environment`. */
808
839
  noiseCheck?: boolean;
840
+ /** Sample the noise floor for exactly this many ms instead. */
841
+ noiseBudgetMs?: number;
809
842
  /**
810
843
  * SIGKILLs a suite file's subprocess (or, under `isolate`, one task's)
811
844
  * that hasn't finished after this many ms. No default. */
@@ -892,8 +925,9 @@ export interface TaskOptions {
892
925
  aliases?: string[];
893
926
  /**
894
927
  * What this task measures and why. Flows into `Workload.description` so
895
- * the intent travels with the numbers instead of living only in a source
896
- * comment. */
928
+ * the intent travels with the numbers instead of living only in a
929
+ * source comment.
930
+ */
897
931
  description?: string;
898
932
  /**
899
933
  * Give this task its own subprocess instead of sharing its suite file's,
@@ -944,8 +978,9 @@ export interface TaskOptions {
944
978
  export interface GroupFn extends GroupRegistrar {
945
979
  /**
946
980
  * Registers every task inside as skipped: the runner never measures
947
- * them, but the document still carries their workloads (marked
948
- * `Workload.skipped`). */
981
+ * them, but the document still carries their workloads
982
+ * (marked `Workload.skipped`).
983
+ */
949
984
  skip: GroupRegistrar;
950
985
  /**
951
986
  * When any task or group in the suite uses `.only`, the runner restricts
@@ -998,9 +1033,11 @@ interface InprocessTimingOptions {
998
1033
  /** Keep sampling past the budget until this many trials exist. When unset
999
1034
  * the floor is cost-aware (see `defaultSampleFloor`). */
1000
1035
  minSamples?: number;
1001
- /** Warmup budget as a fraction of `budgetMs` (default: 0.1); unlike
1002
- * `time()`'s `warmup`, which is a trial count. Always runs at least one
1003
- * call. */
1036
+ /**
1037
+ * Warmup budget as a fraction of `budgetMs` (default: 0.1); unlike
1038
+ * `time()`'s `warmup`, which is a trial count. Always runs at least
1039
+ * one call.
1040
+ */
1004
1041
  warmup?: number;
1005
1042
  gc?: boolean;
1006
1043
  }
@@ -1012,7 +1049,9 @@ export interface RunOptions extends MeasureTasksOpts {
1012
1049
  /** Renderer used for the printed report (default: `"table"`). */
1013
1050
  format?: FormatName;
1014
1051
  }
1015
- export type FormatName = "table" | "json" | "markdown" | "jsonl" | "minimal" | "collapsed" | "mermaid" | "speedscope" | "cpuprofile";
1052
+ export type FormatName = "table" | "json" | "markdown" | "jsonl" | "events"
1053
+ /** `events`, by the name it had until 0.5.0. */
1054
+ | "minimal" | "concise" | "collapsed" | "mermaid" | "speedscope" | "cpuprofile";
1016
1055
  /** In-file entrypoint: call at the bottom of a suite file run directly with
1017
1056
  * `bun suite.ts` to measure every registered `group()`/`task()`, print a
1018
1057
  * report, and return the document.
@@ -1079,8 +1118,9 @@ export interface AbConfig {
1079
1118
  * `--base-setup` replaces this list. */
1080
1119
  setup?: string | string[];
1081
1120
  /**
1082
- * Base trees to keep cached; see `AbOptions.keepTrees`. `--keep-trees`
1083
- * overrides. Default: 5. */
1121
+ * Base trees to keep cached; see `AbOptions.keepTrees`.
1122
+ * `--keep-trees` overrides. Default: 5.
1123
+ */
1084
1124
  keepTrees?: number;
1085
1125
  /**
1086
1126
  * Judge rounds by `"time"` or `"instructions"`; see `AbOptions.metric`.
@@ -1188,12 +1228,14 @@ export interface WorkloadConfig {
1188
1228
  /**
1189
1229
  * `command`: kills a trial (or prepare hook) after this many ms.
1190
1230
  * `suites`: kills a suite file's (or isolated task's) process after this
1191
- * many ms, overriding `bench.timeoutMs`. Overrides `ostia ci`'s 10-minute
1192
- * default. */
1231
+ * many ms, overriding `bench.timeoutMs`. Overrides `ostia ci`'s
1232
+ * 10-minute default.
1233
+ */
1193
1234
  timeoutMs?: number;
1194
1235
  /**
1195
- * `command` only. Exit codes to treat as success; see
1196
- * `TimeOptions.ignoreExitCodes`. */
1236
+ * `command` only. Exit codes to treat as success;
1237
+ * see `TimeOptions.ignoreExitCodes`.
1238
+ */
1197
1239
  ignoreExitCodes?: number[];
1198
1240
  }
1199
1241
  /**
@@ -1258,9 +1300,11 @@ export declare class OstiaDocumentError extends Error {
1258
1300
  * truncated file.
1259
1301
  */
1260
1302
  export declare function saveDocument(doc: ProfileDocument, path: string): Promise<void>;
1261
- /** Pins `value` against dead-code elimination for an intermediate inside a
1262
- * task body. A task's own return value is already pinned by the timing
1263
- * loop. */
1303
+ /**
1304
+ * Pins `value` against dead-code elimination for an intermediate inside a
1305
+ * task body. A task's own return value is already pinned by the
1306
+ * timing loop.
1307
+ */
1264
1308
  export declare function keep(value: unknown): void;
1265
1309
  export interface ProfileOptions {
1266
1310
  /**
@@ -1270,8 +1314,9 @@ export interface ProfileOptions {
1270
1314
  /**
1271
1315
  * Names the workload: it becomes the label and, instead of the function's
1272
1316
  * name and source, what the id hashes, so closures that differ only in
1273
- * captured values get distinct ids and the id survives editing the
1274
- * function. */
1317
+ * captured values get distinct ids and the id survives editing
1318
+ * the function.
1319
+ */
1275
1320
  name?: string;
1276
1321
  /**
1277
1322
  * `"inspector"` (default) captures through CDP and writes a portable
@@ -1281,8 +1326,9 @@ export interface ProfileOptions {
1281
1326
  /**
1282
1327
  * There's no child to kill, so an already-aborted signal skips the
1283
1328
  * profiler, calls `fn` plain (still returning its `result`) and records an
1284
- * `aborted` warning instead of CPU evidence. It can't interrupt a running
1285
- * `fn`. */
1329
+ * `aborted` warning instead of CPU evidence. It can't interrupt a
1330
+ * running `fn`.
1331
+ */
1286
1332
  signal?: AbortSignal;
1287
1333
  }
1288
1334
  export interface ProfileResult<T> {
@@ -1300,7 +1346,10 @@ export declare const renderers: {
1300
1346
  json: Renderer;
1301
1347
  markdown: Renderer;
1302
1348
  jsonl: Renderer;
1349
+ events: Renderer<MinimalRenderOptions>;
1350
+ /** `events`, by the name it had until 0.5.0. */
1303
1351
  minimal: Renderer<MinimalRenderOptions>;
1352
+ concise: Renderer;
1304
1353
  collapsed: Renderer<VizOptions>;
1305
1354
  mermaid: Renderer<MermaidOptions>;
1306
1355
  speedscope: Renderer<VizOptions>;
@@ -1323,8 +1372,9 @@ export interface MinimalRenderOptions {
1323
1372
  /**
1324
1373
  * What the `unmatched`/`summary` events need beyond one `ProfileDocument`.
1325
1374
  * The CLI builds it for `compare`/`ci`/`ab`; without it `minimal` emits
1326
- * only `run` lines. `exitCode` is inline because the CLI decides it after
1327
- * rendering. */
1375
+ * only `run` lines. `exitCode` is inline because the CLI decides it
1376
+ * after rendering.
1377
+ */
1328
1378
  export interface MinimalProtocolContext {
1329
1379
  command: "compare" | "ci" | "ab";
1330
1380
  exitCode: number;
@@ -1370,8 +1420,8 @@ export interface MinimalRunLine {
1370
1420
  groupDescription?: string;
1371
1421
  params?: Record<string, string | number | boolean>;
1372
1422
  /**
1373
- * `task.skip()` / `group.skip()`: no measurement, so every stats field is
1374
- * absent.
1423
+ * `task.skip()` / `group.skip()`: no measurement, so every stats field
1424
+ * is absent.
1375
1425
  */
1376
1426
  skipped?: true;
1377
1427
  unit?: "ns";
@@ -1541,8 +1591,8 @@ export interface MinimalSummaryLine {
1541
1591
  /** `ab` only: the gate on `geomeanPct`. */
1542
1592
  geomeanThresholdPct?: number;
1543
1593
  /**
1544
- * `ab` only: flagged in the first process but not reproduced; counted in
1545
- * `unchanged`.
1594
+ * `ab` only: flagged in the first process but not reproduced; counted
1595
+ * in `unchanged`.
1546
1596
  */
1547
1597
  unconfirmed?: number;
1548
1598
  /**
@@ -1590,6 +1640,23 @@ export interface CommandSpec {
1590
1640
  }
1591
1641
  export interface TimeOptions {
1592
1642
  commands: (string | string[] | CommandSpec)[];
1643
+ /**
1644
+ * Run each string command, and a string `prepare`, as `shell -c COMMAND`
1645
+ * (`"sh"`, `"bash"`) instead of splitting it on whitespace, so env
1646
+ * prefixes, pipes, `&&` and `$(...)` work. An argv array runs as given.
1647
+ * The shell's own startup is measured and recorded as `doc.shell`,
1648
+ * not subtracted.
1649
+ */
1650
+ shell?: string;
1651
+ /**
1652
+ * Save each trial's stdout and stderr under this directory, one folder
1653
+ * per command (its label, made safe for a path, and its id), as
1654
+ * `trial-N.log` and `warmup-N.log`; each trial's `outputPath` names
1655
+ * its file.
1656
+ */
1657
+ saveOutput?: string;
1658
+ /** Pass each trial's output to stderr, for debugging. */
1659
+ showOutput?: boolean;
1593
1660
  /**
1594
1661
  * Runs unmeasured before every trial (warmup and instrumented included),
1595
1662
  * in `cwd`/`env`: a command spawned and awaited, or a function. */
@@ -1609,8 +1676,9 @@ export interface TimeOptions {
1609
1676
  warmup?: number;
1610
1677
  /**
1611
1678
  * Round-robin trials across commands instead of finishing each command
1612
- * first, so drift hits every command equally. Default: true with 2+
1613
- * commands. */
1679
+ * first, so drift hits every command equally. Default: true with
1680
+ * 2+ commands.
1681
+ */
1614
1682
  interleave?: boolean;
1615
1683
  cwd?: string;
1616
1684
  env?: Record<string, string>;
@@ -1619,9 +1687,11 @@ export interface TimeOptions {
1619
1687
  cpuIntervalUs?: number;
1620
1688
  outDir?: string;
1621
1689
  /**
1622
- * Measure the machine's noise floor first (default true, ~200ms) and stamp
1623
- * it on the document as `environment`. */
1690
+ * Measure the machine's noise floor first (default true, 25 to 50 ms) and
1691
+ * stamp it on the document as `environment`. */
1624
1692
  noiseCheck?: boolean;
1693
+ /** Sample the noise floor for exactly this many ms instead. */
1694
+ noiseBudgetMs?: number;
1625
1695
  /**
1626
1696
  * SIGKILLs a trial (or prepare hook) still running after this many ms. No
1627
1697
  * default. A timed-out trial contributes no sample. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ostia",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Fast profiling and benchmarking for Bun.",
5
5
  "license": "MIT",
6
6
  "author": "Eric Liu (https://github.com/metonym)",
@@ -112,8 +112,8 @@ async function importTasks(suiteFile: string): Promise<RegisteredTask[]> {
112
112
  return [...getRegisteredTasks()];
113
113
  }
114
114
 
115
- // The parent writes optsJson, so this checks only the fields every run
116
- // reads.
115
+ // The parent writes optsJson, so this checks only the fields every
116
+ // run reads.
117
117
  function isRunnerOpts(v: unknown): v is AbRunnerOpts {
118
118
  return (
119
119
  typeof v === "object" &&
@@ -157,8 +157,8 @@ type MeasureOutcome =
157
157
  // `before` threw isn't timed or torn down. Every side that was set up is
158
158
  // torn down once, in reverse order, even when a hook throws. When only one
159
159
  // side has thrown, the other side's task is called once more, before
160
- // teardown and only if that side is set up, to tell whether it throws too
161
- // (`"both"`).
160
+ // teardown and only if that side is set up, to tell whether it throws
161
+ // too (`"both"`).
162
162
  async function measureTask(
163
163
  base: RegisteredTask,
164
164
  cand: RegisteredTask,
@@ -302,8 +302,8 @@ async function measureMemory(
302
302
  // in this process. Each side is imported from its own path so its relative
303
303
  // imports resolve within its own tree, while bare imports (including
304
304
  // `ostia`, hence the shared registry) share `node_modules`. `baseSuite` is
305
- // "" when the file doesn't exist at the base ref: every task is
306
- // candidate-only.
305
+ // "" when the file doesn't exist at the base ref: every task
306
+ // is candidate-only.
307
307
  async function main(): Promise<number> {
308
308
  const [candSuite, baseSuite, outputPath, optsJson] = process.argv.slice(2);
309
309
  if (!candSuite || baseSuite === undefined || !outputPath || !optsJson) {
package/src/ab/index.ts CHANGED
@@ -110,15 +110,19 @@ export interface AbOptions {
110
110
  outDir?: string;
111
111
  cwd?: string;
112
112
  noiseCheck?: boolean;
113
+ /** Sample the noise floor for exactly this many ms instead. */
114
+ noiseBudgetMs?: number;
113
115
  /** Also compare each side's retained heap per call (see
114
116
  * `bench({ alloc })`) and how far its first call raises RSS (see
115
117
  * `bench({ peakMem })`), each the median of 3 fresh processes per side.
116
118
  * Task/group options override these. */
117
119
  alloc?: boolean;
118
120
  peakMem?: boolean;
119
- /** Flag a memory reading that moves past this many percent of the base's
120
- * and past its noise floor (default: 10). A memory regression fails the
121
- * run. */
121
+ /**
122
+ * Flag a memory reading that moves past this many percent of the base's
123
+ * and past its noise floor (default: 10). A memory regression fails
124
+ * the run.
125
+ */
122
126
  memThresholdPct?: number;
123
127
  /** Shell commands run once, in order, in a freshly extracted base tree
124
128
  * before it's used: to build what the suites import but git doesn't hold
@@ -215,8 +219,10 @@ async function saltScripts(dir: string): Promise<void> {
215
219
 
216
220
  interface TreeSetup {
217
221
  commands: string[];
218
- /** The project root and the directory `ab()` runs from, in the working
219
- * tree. */
222
+ /**
223
+ * The project root and the directory `ab()` runs from, in the
224
+ * working tree.
225
+ */
220
226
  toplevel: string;
221
227
  cwd: string;
222
228
  timeoutMs?: number | undefined;
@@ -863,7 +869,10 @@ export async function ab(opts: AbOptions): Promise<ProfileDocument> {
863
869
  return doc;
864
870
  }
865
871
 
866
- const { environment, noiseWarning } = captureRunEnvironment(opts.noiseCheck);
872
+ const { environment, noiseWarning } = captureRunEnvironment(
873
+ opts.noiseCheck,
874
+ opts.noiseBudgetMs,
875
+ );
867
876
 
868
877
  // "" when the file doesn't exist at the base ref: all its tasks are new.
869
878
  const baseSuites = candSuites.map((suite, i) => {
@@ -94,6 +94,8 @@ export interface BenchOptions {
94
94
  * Measure this machine's noise floor once, before any suite runs
95
95
  * (default: true), and stamp it on the document as `environment`. */
96
96
  noiseCheck?: boolean;
97
+ /** Sample the noise floor for exactly this many ms instead. */
98
+ noiseBudgetMs?: number;
97
99
  /**
98
100
  * SIGKILLs a suite file's subprocess (or, under `isolate`, one task's)
99
101
  * that hasn't finished after this many ms. No default. */
@@ -132,6 +134,7 @@ export interface BenchCliOverrides {
132
134
  bunFlags: string[];
133
135
  outDir?: string;
134
136
  noiseCheck: boolean;
137
+ noiseBudgetMs?: number;
135
138
  timeoutMs?: number;
136
139
  }
137
140
 
@@ -190,6 +193,9 @@ export async function resolveBenchOptions(
190
193
  ...(projects !== undefined && { projects }),
191
194
  ...(outDir !== undefined && { outDir }),
192
195
  noiseCheck: cli.noiseCheck,
196
+ ...(cli.noiseBudgetMs !== undefined && {
197
+ noiseBudgetMs: cli.noiseBudgetMs,
198
+ }),
193
199
  ...(timeoutMs !== undefined && { timeoutMs }),
194
200
  cwd,
195
201
  };
@@ -274,7 +280,10 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
274
280
  const path = absolutePath(cwd, given);
275
281
  return { given, path, ...launch(path) };
276
282
  });
277
- const { environment, noiseWarning } = captureRunEnvironment(opts.noiseCheck);
283
+ const { environment, noiseWarning } = captureRunEnvironment(
284
+ opts.noiseCheck,
285
+ opts.noiseBudgetMs,
286
+ );
278
287
 
279
288
  const measureOpts: RunnerOpts = {
280
289
  ...(opts.budgetMs !== undefined && { budgetMs: opts.budgetMs }),
@@ -466,8 +475,8 @@ export async function bench(opts: BenchOptions): Promise<ProfileDocument> {
466
475
 
467
476
  // Plan order (registration order, filtered) within a suite, suites in
468
477
  // command-line order. Measurements are matched by workload id, not
469
- // position, because a task.skip()'d task has a workload but no
470
- // measurement.
478
+ // position, because a task.skip()'d task has a workload but
479
+ // no measurement.
471
480
  const workloads: Workload[] = [];
472
481
  const measurements: Measurement[] = [];
473
482
  for (const { suite, tasks, doc: sharedDoc } of plans) {
@@ -29,8 +29,9 @@ export interface TaskOptions {
29
29
  aliases?: string[];
30
30
  /**
31
31
  * What this task measures and why. Flows into `Workload.description` so
32
- * the intent travels with the numbers instead of living only in a source
33
- * comment. */
32
+ * the intent travels with the numbers instead of living only in a
33
+ * source comment.
34
+ */
34
35
  description?: string;
35
36
  /**
36
37
  * Give this task its own subprocess instead of sharing its suite file's,
@@ -210,8 +211,9 @@ type GroupRegistrar = (
210
211
  export interface GroupFn extends GroupRegistrar {
211
212
  /**
212
213
  * Registers every task inside as skipped: the runner never measures
213
- * them, but the document still carries their workloads (marked
214
- * `Workload.skipped`). */
214
+ * them, but the document still carries their workloads
215
+ * (marked `Workload.skipped`).
216
+ */
215
217
  skip: GroupRegistrar;
216
218
  /**
217
219
  * When any task or group in the suite uses `.only`, the runner restricts
@@ -49,8 +49,8 @@ export interface MeasureTasksOpts extends InprocessTimingOptions {
49
49
  noiseCheck?: boolean;
50
50
  }
51
51
 
52
- // Shared by every runner so a task has the same id under `bench()` and
53
- // `ab()`.
52
+ // Shared by every runner so a task has the same id under `bench()`
53
+ // and `ab()`.
54
54
  export function taskWorkload(
55
55
  suiteFile: string,
56
56
  t: RegisteredTask,
@@ -57,8 +57,8 @@ export interface RunnerOpts extends MeasureTasksOpts {
57
57
  preload?: string[];
58
58
  }
59
59
 
60
- // The parent serializes a `RunnerOpts`; only that it's an object is
61
- // checked.
60
+ // The parent serializes a `RunnerOpts`; only that it's an object
61
+ // is checked.
62
62
  function isRunnerOpts(value: unknown): value is RunnerOpts {
63
63
  return typeof value === "object" && value !== null && !Array.isArray(value);
64
64
  }
@@ -56,8 +56,8 @@ export async function loadIfExists(
56
56
  return (await Bun.file(path).exists()) ? loadDocument(path) : undefined;
57
57
  }
58
58
 
59
- // invariant: a `--peak-mem` reading is the median of this many fresh
60
- // processes.
59
+ // invariant: a `--peak-mem` reading is the median of this many
60
+ // fresh processes.
61
61
  export const PEAK_MEM_PROCESSES = 3;
62
62
  // Slack below this is what any suite that loads fixtures leaves behind
63
63
  // (8MB for caligula's), so it's too common to warn about.
@@ -76,11 +76,15 @@ export function peakHiddenWarning(
76
76
  };
77
77
  }
78
78
 
79
- export function captureRunEnvironment(noiseCheck: boolean | undefined): {
79
+ export function captureRunEnvironment(
80
+ noiseCheck: boolean | undefined,
81
+ noiseBudgetMs?: number,
82
+ ): {
80
83
  environment: Environment | undefined;
81
84
  noiseWarning: Warning | undefined;
82
85
  } {
83
- const environment = noiseCheck === false ? undefined : captureEnvironment();
86
+ const environment =
87
+ noiseCheck === false ? undefined : captureEnvironment(noiseBudgetMs);
84
88
  return {
85
89
  environment,
86
90
  noiseWarning: environment && noisyMachineWarning(environment),