ostia 0.5.0 → 0.6.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.
- package/README.md +27 -26
- package/docs/cli.md +84 -53
- package/docs/document-schema.md +1 -0
- package/docs/library.md +15 -6
- package/docs/statistics.md +4 -3
- package/index.d.ts +74 -2
- package/package.json +1 -1
- package/src/ab/index.ts +41 -0
- package/src/ab/unpaired.ts +54 -0
- package/src/bench/index.ts +28 -0
- package/src/bench/run-tasks.ts +14 -0
- package/src/bench/runner.ts +8 -1
- package/src/ci/index.ts +32 -42
- package/src/cli/flags.ts +8 -0
- package/src/cli/help.ts +670 -263
- package/src/cli/main.ts +2 -3
- package/src/cli/output.ts +11 -11
- package/src/cli/run.ts +289 -88
- package/src/index.ts +3 -2
- package/src/ir/types.ts +2 -0
- package/src/measure/timing.ts +9 -3
- package/src/renderers/human.ts +402 -0
- package/src/renderers/index.ts +3 -2
- package/src/renderers/terminal.ts +1177 -385
- package/src/terminal.ts +321 -0
- package/src/time.ts +49 -10
package/README.md
CHANGED
|
@@ -13,44 +13,45 @@ and every result is one JSON document.
|
|
|
13
13
|
```ts
|
|
14
14
|
// suite.ts
|
|
15
15
|
import { group, task } from "ostia"
|
|
16
|
+
import { dedupe } from "./dedupe.ts"
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
+
const ids = Array.from({ length: 2_000 }, (_, i) => (i * 7919) % 500)
|
|
18
19
|
|
|
19
|
-
group("
|
|
20
|
-
task("
|
|
21
|
-
task("
|
|
20
|
+
group("ids", () => {
|
|
21
|
+
task("dedupe 2,000", () => dedupe(ids))
|
|
22
|
+
task("sort 2,000", () => ids.toSorted((a, b) => a - b))
|
|
22
23
|
})
|
|
23
24
|
```
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Task Median Spread Range Relative
|
|
30
|
-
-----------------------------------------------------------------------------------------
|
|
31
|
-
dedupe:
|
|
32
|
-
naive (indexOf scan, O(n²)) 173.9 µs 180.4 µs…205.8 µs 170.1 µs…635.5 µs 7.40× slower
|
|
33
|
-
Set-based (O(n)) 23.5 µs 24.9 µs…72.5 µs 18.7 µs…208.3 µs 1.00×
|
|
34
|
-
```
|
|
26
|
+
<picture>
|
|
27
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/ostia/master/.github/assets/bench-dark.png">
|
|
28
|
+
<img alt="ostia bench suite.ts: 2 tasks, fastest dedupe 2,000 at 21.6 µs, sort 2,000 at 123 µs, each with its noise and instructions per call" src="https://raw.githubusercontent.com/metonym/ostia/master/.github/assets/bench-light.png">
|
|
29
|
+
</picture>
|
|
35
30
|
|
|
36
31
|
**It tells you when a change made something slower.**
|
|
37
|
-
|
|
38
|
-
and
|
|
32
|
+
Rewrite `dedupe` from a `Set` to `indexOf`,
|
|
33
|
+
and `ostia ab` runs your suite against `HEAD` and the working tree in
|
|
34
|
+
alternating batches in one process:
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
<picture>
|
|
37
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/ostia/master/.github/assets/ab-dark.png">
|
|
38
|
+
<img alt="ostia ab suite.ts after dedupe moved from a Set to indexOf: fail, dedupe 2,000 regressed +207%, confirmed by repeats in fresh processes, sort 2,000 unchanged, ending with the command to profile it" src="https://raw.githubusercontent.com/metonym/ostia/master/.github/assets/ab-light.png">
|
|
39
|
+
</picture>
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
------------------------------------------------------------------------------------------
|
|
46
|
-
dedupe:
|
|
47
|
-
naive (indexOf scan, O(n²)) 183.5 µs 178.5 µs -1.9% -3.5%…-0.3%
|
|
48
|
-
Set-based (O(n)) 25.2 µs 181.2 µs +618.1% +554.2%…+659.2% regressed, confirmed (repeats: +630.6%, +584.5%)
|
|
41
|
+
While it runs, one line says where it is:
|
|
49
42
|
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
<picture>
|
|
44
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/ostia/master/.github/assets/progress-dark.png">
|
|
45
|
+
<img alt="ostia ab's progress line: a bar at task 2 of 2, ids/sort 2,000" src="https://raw.githubusercontent.com/metonym/ostia/master/.github/assets/progress-light.png">
|
|
46
|
+
</picture>
|
|
52
47
|
|
|
53
48
|
Exit 1 on a regression, so CI can gate on it.
|
|
49
|
+
`ostia time` does the same for whole commands:
|
|
50
|
+
|
|
51
|
+
<picture>
|
|
52
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/ostia/master/.github/assets/time-dark.png">
|
|
53
|
+
<img alt="ostia time on gzip -1 and gzip -9 of the same file: gzip -1 is 12.9 times faster, with each command's noise and user and system time" src="https://raw.githubusercontent.com/metonym/ostia/master/.github/assets/time-light.png">
|
|
54
|
+
</picture>
|
|
54
55
|
ostia has no dependencies and needs Bun ≥ 1.4.
|
|
55
56
|
|
|
56
57
|
## Quick start
|
package/docs/cli.md
CHANGED
|
@@ -79,6 +79,7 @@ ostia time [flags] -- <argv...>
|
|
|
79
79
|
| `--export-json PATH` | Write the document to `PATH`. |
|
|
80
80
|
| `--format FORMAT` | `table`, `concise`, `events`, `json`, `jsonl`, `markdown`; `--json` for `--format json`. |
|
|
81
81
|
| `--quiet` | Don't print the report. |
|
|
82
|
+
| `--color` / `--no-color` | Force color in the table on or off. Default: on when stdout is a terminal no coding agent reads, and `NO_COLOR` isn't set. |
|
|
82
83
|
|
|
83
84
|
### Commands
|
|
84
85
|
|
|
@@ -196,21 +197,19 @@ The raw `.cpuprofile` / `.heapsnapshot` is written
|
|
|
196
197
|
under `<out-dir>/artifacts/`.
|
|
197
198
|
|
|
198
199
|
```
|
|
199
|
-
CPU
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
105 hidden
|
|
213
|
-
artifact: /tmp/ostia-heap/artifacts/run_608f71a09a849cca-heap.heapsnapshot
|
|
200
|
+
CPU profile bun fixtures/work.ts · 14 samples at 1.00 ms
|
|
201
|
+
function self share
|
|
202
|
+
hotInner 21.0 ms 100%
|
|
203
|
+
/tmp/ostia-hot/artifacts/run_6dbc7f8302eedc8c-cpu.cpuprofile
|
|
204
|
+
|
|
205
|
+
Heap snapshot bun fixtures/work.ts · 1.53K objects · 109 KiB
|
|
206
|
+
type objects
|
|
207
|
+
code 430
|
|
208
|
+
string 344
|
|
209
|
+
closure 326
|
|
210
|
+
object shape 218
|
|
211
|
+
hidden 129
|
|
212
|
+
/tmp/ostia-hot/artifacts/run_6dbc7f8302eedc8c-heap.heapsnapshot
|
|
214
213
|
```
|
|
215
214
|
|
|
216
215
|
Use `ostia report --format collapsed|mermaid|speedscope|cpuprofile` on
|
|
@@ -245,6 +244,7 @@ ostia bench [flags] <suite.ts...>
|
|
|
245
244
|
| `--export-json PATH` | Write the document to `PATH`. |
|
|
246
245
|
| `--format FORMAT` | `table`, `concise`, `events`, `json`, `jsonl`, `markdown`; `--json` for `--format json`. |
|
|
247
246
|
| `--quiet` | Don't print the report. |
|
|
247
|
+
| `--color` / `--no-color` | Force color in the table on or off. Default: on when stdout is a terminal no coding agent reads, and `NO_COLOR` isn't set. |
|
|
248
248
|
|
|
249
249
|
With no suite files, `ostia bench` uses the config's `bench` section
|
|
250
250
|
(`suites` globs and the rest).
|
|
@@ -395,17 +395,16 @@ this slack, so read small differences with that in mind;
|
|
|
395
395
|
`--peak-mem` is for calls that allocate megabytes.
|
|
396
396
|
|
|
397
397
|
```
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
retains 8KB/call 819.4 ns 1027.8 ns…20563.9 ns 493.1 ns…357930.6 ns 7.58KiB 48.00KiB 2731.39× slower
|
|
404
|
-
noop 0.30 ns 0.31 ns…0.42 ns 0.29 ns…5.40 ns 0B 0B 1.00×
|
|
398
|
+
task median noise instr/call retained/op peak mem vs fastest
|
|
399
|
+
mem
|
|
400
|
+
├ garbage 40MB 3.10 ms ±35.8% 18.1M 222 B 38.3 MiB 5.34M×
|
|
401
|
+
├ retains… 1.93 µs ±20.2% 9.24K 7.73 KiB 0 B 3.33K×
|
|
402
|
+
└ noop 0.58 ns ±8.8% 7 0 B 0 B fastest
|
|
405
403
|
```
|
|
406
404
|
|
|
407
405
|
The first task allocates and drops a 40MB array per call:
|
|
408
|
-
`
|
|
406
|
+
`retained/op` sees nothing, `peak mem` sees all of it.
|
|
407
|
+
A name that would push a row past 80 columns is cut at a word.
|
|
409
408
|
The second keeps 8KB per call alive, which both see.
|
|
410
409
|
Byte counts print 1024-based (`B`, `KiB`, `MiB`) everywhere,
|
|
411
410
|
heap snapshot summaries included.
|
|
@@ -464,11 +463,20 @@ Space-separated flags within one value are split and all passed.
|
|
|
464
463
|
|
|
465
464
|
### Table layout
|
|
466
465
|
|
|
467
|
-
|
|
466
|
+
The first line is the verdict: how many tasks, the fastest and its time,
|
|
467
|
+
and how many warnings.
|
|
468
|
+
A dim line under it names the machine and the suite.
|
|
469
|
+
Grouped tasks print under their group's name, as a tree;
|
|
468
470
|
ungrouped tasks and subprocess commands print flat.
|
|
469
|
-
`
|
|
470
|
-
task
|
|
471
|
-
|
|
471
|
+
`noise` is ± the median absolute deviation, as a percent of the median.
|
|
472
|
+
`vs fastest` compares each task with its group's fastest task;
|
|
473
|
+
when a group has a `{ baseline: true }` task,
|
|
474
|
+
the column is `vs baseline` and compares with that.
|
|
475
|
+
A warning prints in words under its row,
|
|
476
|
+
with its fix where there is one; outliers print gray
|
|
477
|
+
unless dropping them moves the median past the noise.
|
|
478
|
+
The spread (p75…p99) and range stay in `--json` and `markdown`.
|
|
479
|
+
`instr/call` is the median number of instructions each call retired,
|
|
472
480
|
where the machine counts them (see `ostia ab`'s "Instructions"):
|
|
473
481
|
unlike time, it barely moves on a loaded machine.
|
|
474
482
|
|
|
@@ -509,8 +517,9 @@ ostia ab [flags] <suite.ts...>
|
|
|
509
517
|
| `--noise-budget MS` | Sample the noise floor for exactly `MS` at the start and at the end, with no early stop. |
|
|
510
518
|
| `--export-json PATH` | Write the document to `PATH`. |
|
|
511
519
|
| `--format FORMAT` | `table`, `concise`, `events`, `json`, `jsonl`, `markdown`; `--json` for `--format json`. |
|
|
512
|
-
| `--progress` / `--no-progress` | Print progress to stderr. Default: on when stderr is a terminal and `--quiet` isn't given. |
|
|
520
|
+
| `--progress` / `--no-progress` | Print progress to stderr. Default: on when stderr is a terminal, the format is `table`, no coding agent runs it, and `--quiet` isn't given. |
|
|
513
521
|
| `--quiet` | Don't print the report. |
|
|
522
|
+
| `--color` / `--no-color` | Force color in the table on or off. Default: on when stdout is a terminal no coding agent reads, and `NO_COLOR` isn't set. |
|
|
514
523
|
|
|
515
524
|
`ostia ab` answers "did my change make this slower?"
|
|
516
525
|
on a machine too noisy for two runs minutes apart to agree.
|
|
@@ -533,20 +542,31 @@ ostia ab bench/*.ts --filter 'source map' --rounds 21
|
|
|
533
542
|
```
|
|
534
543
|
|
|
535
544
|
```
|
|
536
|
-
|
|
545
|
+
fail · 1 regressed · geomean +76.2% · 1 unchanged
|
|
546
|
+
HEAD 26e7d0d vs working tree · 15 rounds · thresholds 10%, geomean 1.5%
|
|
537
547
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
548
|
+
task base candidate change noise instr verdict
|
|
549
|
+
dedupe
|
|
550
|
+
├ naive (indexOf scan… 131 µs 147 µs ~0% ±13.3% 0.0%
|
|
551
|
+
└ Set-based (O(n)) 47.8 µs 141 µs +201% ±22.2% +257% regressed
|
|
552
|
+
repeats +166%, +289%
|
|
543
553
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
Geomean +41.0% (threshold 1.5%) · 1 regressed, 0 improved, 1 unchanged of 2 · fail
|
|
554
|
+
✗ A/B fails: dedupe/Set-based (O(n)) regressed +201%
|
|
555
|
+
profile it: ostia bench suite.ts --cpu --filter 'dedupe/Set-based \(O\(n\)\)'
|
|
548
556
|
```
|
|
549
557
|
|
|
558
|
+
The first line is the gate's verdict.
|
|
559
|
+
`change` is the median of the per-round ratios,
|
|
560
|
+
and `noise` their median absolute deviation;
|
|
561
|
+
a change inside the noise reads `~0%`.
|
|
562
|
+
Past 10×, a change prints as a multiple (`501×`).
|
|
563
|
+
Color marks only what the gate judged: green improved, red regressed.
|
|
564
|
+
A flagged task that a fresh process didn't confirm reads `regressed?`
|
|
565
|
+
and stays out of the verdict.
|
|
566
|
+
Repeats, a changed output, memory readings and warnings print under the
|
|
567
|
+
task's row.
|
|
568
|
+
The last line names what failed and the next step.
|
|
569
|
+
|
|
550
570
|
**The base tree.**
|
|
551
571
|
The ref's commit is extracted with `git archive` into `.ostia/ab/<sha>/`
|
|
552
572
|
at the project root (the first 12 characters of the sha) once
|
|
@@ -813,23 +833,29 @@ A memory regression fails the run like a time regression.
|
|
|
813
833
|
Task and group `alloc`/`peakMem` options apply under `ab` as
|
|
814
834
|
under `bench`.
|
|
815
835
|
A task that's not comparable gets no memory verdict.
|
|
816
|
-
|
|
817
|
-
|
|
836
|
+
Each reading prints under its task's row,
|
|
837
|
+
with its verdict when it moved past the threshold;
|
|
838
|
+
a reading that moved less than 10% and wasn't judged isn't shown.
|
|
818
839
|
|
|
819
840
|
```
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
remember
|
|
841
|
+
task base candidate change noise instr verdict
|
|
842
|
+
dom
|
|
843
|
+
├ paint 574 µs 75.8 µs -85.7% ±39.7% -87.2% not comparable
|
|
844
|
+
retained/op 10 B → 8 B (-23.2%)
|
|
845
|
+
peak 7.73 MiB → 559 KiB (-92.9%)
|
|
846
|
+
the suite and its output both changed, so it isn't judged
|
|
847
|
+
└ remember 3.46 ns 1.88 µs 501× ±38.1% 156× regressed
|
|
848
|
+
repeats 433×, 336×
|
|
849
|
+
retained/op 22 B → 7.89 KiB (370×) regressed
|
|
827
850
|
```
|
|
828
851
|
|
|
829
852
|
**Progress.**
|
|
830
853
|
A run over many suites, with confirmations, can take many minutes.
|
|
831
854
|
On a terminal, `ostia ab` shows one progress line on stderr,
|
|
832
|
-
|
|
855
|
+
a bar of how far it is, the step and the seconds,
|
|
856
|
+
replaced as it goes and cleared before the report;
|
|
857
|
+
`time`, `bench` and `ci` do the same.
|
|
858
|
+
A coding agent and a format other than `table` get none.
|
|
833
859
|
`--progress` turns it on anywhere else too, as one line per step,
|
|
834
860
|
which is how a script or agent can tell a long run from a stuck one:
|
|
835
861
|
|
|
@@ -875,6 +901,7 @@ ostia compare <candidate.json> --baseline <base.json>
|
|
|
875
901
|
| `--export-json PATH` | Write the candidate document, with comparisons, to `PATH`. |
|
|
876
902
|
| `--format FORMAT` | `table`, `concise`, `events`, `json`, `jsonl`, `markdown`; `--json` for `--format json`. |
|
|
877
903
|
| `--quiet` | Don't print the report. |
|
|
904
|
+
| `--color` / `--no-color` | Force color in the table on or off. Default: on when stdout is a terminal no coding agent reads, and `NO_COLOR` isn't set. |
|
|
878
905
|
|
|
879
906
|
Exactly two document paths are taken (one with `--baseline`);
|
|
880
907
|
a third is a usage error.
|
|
@@ -979,6 +1006,7 @@ ostia report <document.json> [flags]
|
|
|
979
1006
|
| Flag | Meaning |
|
|
980
1007
|
|---|---|
|
|
981
1008
|
| `--format FORMAT` | See below (default: `table`). |
|
|
1009
|
+
| `--color` / `--no-color` | Force color in the table on or off. Default: on when stdout is a terminal no coding agent reads, and `NO_COLOR` isn't set. |
|
|
982
1010
|
| `--measurement ID` | Visualization formats only: render only this measurement (default: every CPU measurement). |
|
|
983
1011
|
| `--out-dir PATH` | Visualization formats only: write files here instead of stdout. |
|
|
984
1012
|
|
|
@@ -1045,18 +1073,21 @@ ostia ci [flags]
|
|
|
1045
1073
|
| `--export-json PATH` | Write the candidate document, with comparisons, to `PATH`. |
|
|
1046
1074
|
| `--format FORMAT` | `table`, `concise`, `events`, `json`, `jsonl`, `markdown`; `--json` for `--format json`. |
|
|
1047
1075
|
| `--quiet` | Don't print the report. |
|
|
1076
|
+
| `--color` / `--no-color` | Force color in the table on or off. Default: on when stdout is a terminal no coding agent reads, and `NO_COLOR` isn't set. |
|
|
1048
1077
|
|
|
1049
1078
|
`ostia ci` loads the config ([config.md](config.md)),
|
|
1050
1079
|
measures every workload, compares against `<baselineDir>/<name>.json`,
|
|
1051
1080
|
and gates on the result.
|
|
1052
1081
|
|
|
1053
1082
|
```
|
|
1054
|
-
|
|
1055
|
-
0 cached
|
|
1056
|
-
|
|
1057
|
-
|
|
1083
|
+
pass · 2 unchanged · geomean -9.0%
|
|
1084
|
+
baseline main · 0 cached, 2 executed · threshold 5.0%
|
|
1085
|
+
|
|
1086
|
+
task base candidate change verdict
|
|
1087
|
+
startup 16.1 ms 15.4 ms -4.5%
|
|
1088
|
+
version 12.3 ms 10.7 ms -13.3%
|
|
1058
1089
|
|
|
1059
|
-
Profile CI
|
|
1090
|
+
✓ Profile CI passes · 2 workloads in 384 ms
|
|
1060
1091
|
```
|
|
1061
1092
|
|
|
1062
1093
|
### Workloads
|
package/docs/document-schema.md
CHANGED
|
@@ -209,6 +209,7 @@ table; `--format events` includes `code` and `data`.
|
|
|
209
209
|
| `skipped` | comparison | The candidate task was skipped; treated as unchanged. |
|
|
210
210
|
| `environment-mismatch` | comparison | The documents came from different platforms, Bun versions, or CPUs. |
|
|
211
211
|
| `suite-changed` | `ab` | The suite file's text differs from the base ref's copy, so each side may run a different benchmark. When the output differs too, the task is not comparable: verdict `unchanged`, left out of the geomean. |
|
|
212
|
+
| `repeats-disagree` | `ab` | A flagged task's fresh-process repeats sit 1.5× or more from its paired run, outside the paired rounds' middle half. Another task in the same process can shape how the JIT compiles a function they share; `--filter` measures the task alone. `data`: `factor`, `pairedRatio`, `repeatRatios`. The verdict is unchanged. |
|
|
212
213
|
| `peak-hidden` | `--peak-mem` | Earlier work in the process (module-scope setup, `before` hooks) freed 16 MiB or more that the allocator still held, which the call could reuse without RSS rising, so `peakBytes` can be that much low. `data: { slackBytes, processes }`. |
|
|
213
214
|
|
|
214
215
|
## Files on disk
|
package/docs/library.md
CHANGED
|
@@ -14,9 +14,10 @@ import {
|
|
|
14
14
|
import type {
|
|
15
15
|
ProfileDocument, Workload, Comparison, Warning, WarningCode, CompareResult, Thresholds,
|
|
16
16
|
TaskOptions, GroupOptions, RunOptions, OstiaConfig, OstiaConfigInput, WorkloadConfig,
|
|
17
|
-
TimeOptions, CommandSpec, PrepareHook, PrepareFn, PrepareRun, TimeSource, TimeUnit,
|
|
18
|
-
BenchOptions, AbOptions, ProfileOptions, ProfileResult,
|
|
17
|
+
TimeOptions, TimeProgress, CommandSpec, PrepareHook, PrepareFn, PrepareRun, TimeSource, TimeUnit,
|
|
18
|
+
BenchOptions, BenchProgress, AbOptions, ProfileOptions, ProfileResult,
|
|
19
19
|
MinimalEvent, MinimalRenderOptions, MinimalProtocolContext, MermaidOptions, VizOptions,
|
|
20
|
+
TableOptions,
|
|
20
21
|
} from "ostia"
|
|
21
22
|
```
|
|
22
23
|
|
|
@@ -44,6 +45,7 @@ const doc = await time({
|
|
|
44
45
|
timeoutMs: 30_000, // no default
|
|
45
46
|
ignoreExitCodes: [1],
|
|
46
47
|
signal: controller.signal,
|
|
48
|
+
onProgress: (p) => console.error(p), // { command, commands, label, runs, doneRatio }
|
|
47
49
|
})
|
|
48
50
|
```
|
|
49
51
|
|
|
@@ -157,6 +159,8 @@ Each call keeps its scratch files in a directory of its own under
|
|
|
157
159
|
`outDir`, so concurrent calls can share one.
|
|
158
160
|
It also takes a `signal`: aborting kills in-flight suite processes
|
|
159
161
|
and resolves with the suites and tasks that had finished.
|
|
162
|
+
`onProgress` is called before each task is measured,
|
|
163
|
+
with `{ suite, suites, file, task, tasks, label }`.
|
|
160
164
|
|
|
161
165
|
### `TaskOptions`
|
|
162
166
|
|
|
@@ -164,7 +168,7 @@ and resolves with the suites and tasks that had finished.
|
|
|
164
168
|
|---|---|
|
|
165
169
|
| `budgetMs`, `samples`, `minSamples` | Override the suite-wide sampling settings for this task. |
|
|
166
170
|
| `isolate`, `gc`, `cpu`, `alloc`, `peakMem` | Override the suite-wide flag (and the group's) for this task. |
|
|
167
|
-
| `baseline` | This task is the group's
|
|
171
|
+
| `baseline` | This task is the group's reference for the table's `vs baseline` column (default: the group's fastest). |
|
|
168
172
|
| `description` | Stored as `Workload.description` and shown in `events` output. |
|
|
169
173
|
| `aliases` | Former names of the task in the same group. `compare`, `ci` and `ab` match a base measured under any of them, so a rename still compares. |
|
|
170
174
|
| `params` | Structured parameters; part of the workload id. Merged over the current `sweep()` point. |
|
|
@@ -385,13 +389,18 @@ Each renderer's options are typed per format:
|
|
|
385
389
|
(`VizOptions` plus `topN?`), `events`
|
|
386
390
|
and `minimal` take `MinimalRenderOptions`
|
|
387
391
|
(`{ protocol? }`, a `MinimalProtocolContext`, to emit the `unmatched`
|
|
388
|
-
and `summary` events),
|
|
392
|
+
and `summary` events), `table` takes `TableOptions`
|
|
393
|
+
(`{ paint?, ran?, elapsedMs?, compare?, ci? }`: color, the context line
|
|
394
|
+
and the closing line, all optional, plain when absent),
|
|
395
|
+
and the rest take no options (pass `{}`).
|
|
389
396
|
|
|
390
397
|
The `table` and `markdown` renderers agree on grouping
|
|
391
398
|
(a task's `group`, else the part of its id before the last `/`),
|
|
392
399
|
on percent deltas
|
|
393
|
-
(`+3.2%`, `-1.5%`, and `0.0%` with no sign when a delta rounds to zero
|
|
394
|
-
|
|
400
|
+
(`+3.2%`, `-1.5%`, and `0.0%` with no sign when a delta rounds to zero;
|
|
401
|
+
the table prints one past +900% as a multiple),
|
|
402
|
+
on byte counts
|
|
403
|
+
(1024-based `B`/`KiB`/`MiB`; the table puts a space before the unit),
|
|
395
404
|
and on naming a comparison or capture whose workload is missing from the
|
|
396
405
|
document by its raw id.
|
|
397
406
|
|
package/docs/statistics.md
CHANGED
|
@@ -11,9 +11,10 @@ Every timing measurement stores its raw samples plus `mean`, `median`,
|
|
|
11
11
|
(mild: beyond 1.5×IQR from the quartiles; severe: beyond 3×IQR).
|
|
12
12
|
Percentiles interpolate linearly between order statistics.
|
|
13
13
|
|
|
14
|
-
Reports lead with the median
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Reports lead with the median, since wall-clock timings have a long right
|
|
15
|
+
tail that skews the mean and standard deviation.
|
|
16
|
+
The table shows noise as ± the MAD, a percent of the median;
|
|
17
|
+
markdown shows Spread as p75…p99.
|
|
17
18
|
|
|
18
19
|
## Sampling
|
|
19
20
|
|
package/index.d.ts
CHANGED
|
@@ -522,7 +522,8 @@ export declare const WARNING_CODES: readonly [
|
|
|
522
522
|
"time-source-no-match",
|
|
523
523
|
"environment-mismatch",
|
|
524
524
|
"peak-hidden",
|
|
525
|
-
"suite-changed"
|
|
525
|
+
"suite-changed",
|
|
526
|
+
"repeats-disagree"
|
|
526
527
|
];
|
|
527
528
|
interface ArtifactRef {
|
|
528
529
|
id: string;
|
|
@@ -849,6 +850,19 @@ export interface BenchOptions {
|
|
|
849
850
|
* `aborted` warning on the last measurement. A suite killed mid-run is
|
|
850
851
|
* dropped entirely: it only writes its result once, at the end. */
|
|
851
852
|
signal?: AbortSignal;
|
|
853
|
+
/** Called before each task is measured, for a progress line. */
|
|
854
|
+
onProgress?: (progress: BenchProgress) => void;
|
|
855
|
+
}
|
|
856
|
+
/** What `bench()` is doing, for `onProgress`. Counts start at 1. */
|
|
857
|
+
export interface BenchProgress {
|
|
858
|
+
suite: number;
|
|
859
|
+
suites: number;
|
|
860
|
+
/** The suite file, as given. */
|
|
861
|
+
file: string;
|
|
862
|
+
/** The task, among the ones its process measures. */
|
|
863
|
+
task: number;
|
|
864
|
+
tasks: number;
|
|
865
|
+
label: string;
|
|
852
866
|
}
|
|
853
867
|
/** Measures the tasks each of `suites` registers, one subprocess per file. */
|
|
854
868
|
export declare function bench(opts: BenchOptions): Promise<ProfileDocument>;
|
|
@@ -1342,7 +1356,7 @@ export declare function profile<T>(fn: () => T | Promise<T>, opts?: ProfileOptio
|
|
|
1342
1356
|
* the top type, so `satisfies` checks every format is present without
|
|
1343
1357
|
* widening the options. */
|
|
1344
1358
|
export declare const renderers: {
|
|
1345
|
-
table: Renderer
|
|
1359
|
+
table: Renderer<TableOptions>;
|
|
1346
1360
|
json: Renderer;
|
|
1347
1361
|
markdown: Renderer;
|
|
1348
1362
|
jsonl: Renderer;
|
|
@@ -1366,6 +1380,52 @@ interface RenderResult {
|
|
|
1366
1380
|
content: string;
|
|
1367
1381
|
}[];
|
|
1368
1382
|
}
|
|
1383
|
+
/** What the table renderer needs beyond the document, all optional. */
|
|
1384
|
+
export interface TableOptions {
|
|
1385
|
+
/** Color; plain when absent, as for a pipe or a file. */
|
|
1386
|
+
paint?: Paint;
|
|
1387
|
+
/** What was run (suite files), for the context line. */
|
|
1388
|
+
ran?: string;
|
|
1389
|
+
/** The command's wall time, for the closing line. */
|
|
1390
|
+
elapsedMs?: number;
|
|
1391
|
+
/** `compare`: where its thresholds came from, and each side's git state. */
|
|
1392
|
+
compare?: {
|
|
1393
|
+
thresholds: string;
|
|
1394
|
+
baseGit?: GitMetadata | undefined;
|
|
1395
|
+
candGit?: GitMetadata | undefined;
|
|
1396
|
+
};
|
|
1397
|
+
/** `ab` that paired nothing: each side's task count, and why. */
|
|
1398
|
+
unpaired?: Unpaired;
|
|
1399
|
+
/** `ci`: the baseline it gated against, and what the cache saved. */
|
|
1400
|
+
ci?: {
|
|
1401
|
+
baseline: string;
|
|
1402
|
+
workloads: number;
|
|
1403
|
+
cached: number;
|
|
1404
|
+
executed: number;
|
|
1405
|
+
/** Workloads that failed to measure. */
|
|
1406
|
+
failed: readonly string[];
|
|
1407
|
+
missingBaseline: number;
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Color for the human format on a terminal only: the agent format and
|
|
1412
|
+
* JSON are read by programs. Each color marks a verdict or recedes,
|
|
1413
|
+
* never decorates.
|
|
1414
|
+
*/
|
|
1415
|
+
type Paint = {
|
|
1416
|
+
good: (text: string) => string;
|
|
1417
|
+
warn: (text: string) => string;
|
|
1418
|
+
bad: (text: string) => string;
|
|
1419
|
+
dim: (text: string) => string;
|
|
1420
|
+
bold: (text: string) => string;
|
|
1421
|
+
faint: (text: string) => string;
|
|
1422
|
+
};
|
|
1423
|
+
interface Unpaired {
|
|
1424
|
+
/** The failure: each side's task count. */
|
|
1425
|
+
what: string;
|
|
1426
|
+
/** The likeliest cause, and what to do. */
|
|
1427
|
+
next: string;
|
|
1428
|
+
}
|
|
1369
1429
|
export interface MinimalRenderOptions {
|
|
1370
1430
|
protocol?: MinimalProtocolContext;
|
|
1371
1431
|
}
|
|
@@ -1706,6 +1766,18 @@ export interface TimeOptions {
|
|
|
1706
1766
|
* trial still contributes its sample and gets no `nonzero-exit` warning.
|
|
1707
1767
|
* */
|
|
1708
1768
|
ignoreExitCodes?: number[];
|
|
1769
|
+
/** Called after each trial, for a progress line. */
|
|
1770
|
+
onProgress?: (progress: TimeProgress) => void;
|
|
1771
|
+
}
|
|
1772
|
+
/** What `time()` is doing, for `onProgress`. Counts start at 1. */
|
|
1773
|
+
export interface TimeProgress {
|
|
1774
|
+
command: number;
|
|
1775
|
+
commands: number;
|
|
1776
|
+
label: string;
|
|
1777
|
+
/** Trials run so far for this command, warmup excluded. */
|
|
1778
|
+
runs: number;
|
|
1779
|
+
/** How far the whole run is, 0 to 1. */
|
|
1780
|
+
doneRatio: number;
|
|
1709
1781
|
}
|
|
1710
1782
|
/** Times each of `commands` as a subprocess, as `ostia time` does. */
|
|
1711
1783
|
export declare function time(opts: TimeOptions): Promise<ProfileDocument>;
|
package/package.json
CHANGED
package/src/ab/index.ts
CHANGED
|
@@ -687,6 +687,33 @@ export function poolOrders(
|
|
|
687
687
|
}
|
|
688
688
|
|
|
689
689
|
// `metric`'s median ratio over the main run and any fresh-process repeats,
|
|
690
|
+
// A task measured after another that calls the same function can run at
|
|
691
|
+
// a speed the JIT gave it for the other's input, which a fresh process,
|
|
692
|
+
// running only it, doesn't reproduce: so the factor between them, when
|
|
693
|
+
// every repeat falls outside the paired rounds' middle half and they
|
|
694
|
+
// differ by 1.5× or more.
|
|
695
|
+
export function repeatsApart(
|
|
696
|
+
p: PairedEvidence,
|
|
697
|
+
metric: AbSummary["metric"],
|
|
698
|
+
): number | undefined {
|
|
699
|
+
const main = metricRatios(p, metric);
|
|
700
|
+
const repeats = (p.repeats ?? []).flatMap((r) => {
|
|
701
|
+
const ratio = metricRatios(r, metric)?.medianRatio;
|
|
702
|
+
return ratio === undefined ? [] : [ratio];
|
|
703
|
+
});
|
|
704
|
+
if (main === undefined || repeats.length === 0) return undefined;
|
|
705
|
+
const outside = repeats.every((r) => r < main.ratioP25 || r > main.ratioP75);
|
|
706
|
+
const factor = Math.max(
|
|
707
|
+
main.medianRatio / median(repeats),
|
|
708
|
+
median(repeats) / main.medianRatio,
|
|
709
|
+
);
|
|
710
|
+
return outside && factor >= REPEATS_APART ? factor : undefined;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// Below 1.5×, a gap is the ordinary drift between one process and the
|
|
714
|
+
// next; past it, the paired run measured something a fresh one doesn't.
|
|
715
|
+
const REPEATS_APART = 1.5;
|
|
716
|
+
|
|
690
717
|
// so one process's JIT luck moves the geomean less; undefined when the
|
|
691
718
|
// task has no `metric` reading.
|
|
692
719
|
function ratioEstimate(
|
|
@@ -1096,6 +1123,20 @@ export async function ab(opts: AbOptions): Promise<ProfileDocument> {
|
|
|
1096
1123
|
p.repeats.length === confirm &&
|
|
1097
1124
|
p.repeats.every((r) => r.flagged === flagged);
|
|
1098
1125
|
p.verdict = p.confirmed ? flagged : "unchanged";
|
|
1126
|
+
const apart = repeatsApart(p, metric);
|
|
1127
|
+
if (apart !== undefined) {
|
|
1128
|
+
m.warnings.push({
|
|
1129
|
+
code: "repeats-disagree",
|
|
1130
|
+
message: `Fresh-process repeats measured ${apart.toFixed(1)}x apart from the paired run; another task in the same process may shape it. Run it alone with --filter.`,
|
|
1131
|
+
data: {
|
|
1132
|
+
factor: apart,
|
|
1133
|
+
pairedRatio: metricRatios(p, metric)?.medianRatio,
|
|
1134
|
+
repeatRatios: p.repeats.map(
|
|
1135
|
+
(r) => metricRatios(r, metric)?.medianRatio,
|
|
1136
|
+
),
|
|
1137
|
+
},
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1099
1140
|
}
|
|
1100
1141
|
|
|
1101
1142
|
// Memory, for tasks that timed without throwing: each side in its own
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Why `ab` paired nothing, in words a person can act on: each side's task
|
|
2
|
+
// count, then the likeliest cause.
|
|
3
|
+
|
|
4
|
+
// A suite that imports `group` or `task` by a relative path, as one
|
|
5
|
+
// inside ostia's own repository does, has the base ref's copy register
|
|
6
|
+
// its tasks with the base tree's copy of ostia, which the runner never
|
|
7
|
+
// reads, so that side has none.
|
|
8
|
+
const RELATIVE_HARNESS =
|
|
9
|
+
/import\s*\{[^}]*\b(?:group|task)\b[^}]*\}\s*from\s*["']\.{1,2}\/[^"']*["']/;
|
|
10
|
+
|
|
11
|
+
export const importsHarnessRelatively = (suiteText: string): boolean =>
|
|
12
|
+
RELATIVE_HARNESS.test(suiteText);
|
|
13
|
+
|
|
14
|
+
export interface Unpaired {
|
|
15
|
+
/** The failure: each side's task count. */
|
|
16
|
+
what: string;
|
|
17
|
+
/** The likeliest cause, and what to do. */
|
|
18
|
+
next: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function unpairedReason(input: {
|
|
22
|
+
ref: string;
|
|
23
|
+
base: number;
|
|
24
|
+
cand: number;
|
|
25
|
+
/** Every suite is new: none exists at `ref`. */
|
|
26
|
+
allNew: boolean;
|
|
27
|
+
relativeHarness: boolean;
|
|
28
|
+
}): Unpaired {
|
|
29
|
+
const { ref, base, cand } = input;
|
|
30
|
+
const tasks = (n: number) => `${n} ${n === 1 ? "task" : "tasks"}`;
|
|
31
|
+
const what = `Nothing paired: ${ref} has ${tasks(base)}, the working tree ${tasks(cand)}`;
|
|
32
|
+
if (input.allNew) {
|
|
33
|
+
return {
|
|
34
|
+
what,
|
|
35
|
+
next: `no suite exists at ${ref}; time new suites with ostia bench`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (base === 0 && cand > 0 && input.relativeHarness) {
|
|
39
|
+
return {
|
|
40
|
+
what,
|
|
41
|
+
next: `the suite imports ostia by a relative path, so ${ref}'s copy registers with ${ref}'s own ostia; import it as "ostia", or by an absolute path`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (base === 0) {
|
|
45
|
+
return { what, next: `${ref}'s copy of the suite registered no task` };
|
|
46
|
+
}
|
|
47
|
+
if (cand === 0) {
|
|
48
|
+
return { what, next: "the working tree's suite registered no task" };
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
what,
|
|
52
|
+
next: "no task name is on both sides; a renamed task pairs with nothing",
|
|
53
|
+
};
|
|
54
|
+
}
|