ostia 0.2.11 → 0.3.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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -353
  3. package/docs/agent-protocol.md +210 -0
  4. package/docs/cli.md +1196 -0
  5. package/docs/config.md +233 -0
  6. package/docs/document-schema.md +224 -0
  7. package/docs/library.md +421 -0
  8. package/docs/preload-recipes.md +169 -0
  9. package/docs/statistics.md +218 -0
  10. package/index.d.ts +942 -642
  11. package/package.json +16 -14
  12. package/src/ab/ab-runner.ts +474 -0
  13. package/src/ab/index.ts +1086 -0
  14. package/src/baseline/index.ts +75 -0
  15. package/src/bench/index.ts +462 -0
  16. package/src/bench/projects.ts +39 -0
  17. package/src/bench/range.ts +27 -0
  18. package/src/bench/registry.ts +424 -0
  19. package/src/bench/run-tasks.ts +176 -0
  20. package/src/bench/run.ts +51 -0
  21. package/src/bench/runner.ts +147 -0
  22. package/src/bench/support.ts +161 -0
  23. package/src/bench/sweep.ts +39 -0
  24. package/src/cache/fingerprint.ts +59 -0
  25. package/src/cache/store.ts +28 -0
  26. package/src/capture/bunflags.ts +91 -0
  27. package/src/capture/cpu-parse.ts +119 -0
  28. package/src/capture/cpu.ts +44 -0
  29. package/src/capture/frames.ts +54 -0
  30. package/src/capture/heap-parse.ts +86 -0
  31. package/src/capture/heap.ts +32 -0
  32. package/src/capture/inspector.ts +46 -0
  33. package/src/capture/jsc-parse.ts +167 -0
  34. package/src/capture/jsc.ts +35 -0
  35. package/src/capture/sampling.ts +5 -0
  36. package/src/ci/index.ts +416 -0
  37. package/src/cli/flags.ts +264 -0
  38. package/{chunk-scvezzm9.js → src/cli/help.ts} +31 -15
  39. package/src/cli/main.ts +18 -0
  40. package/src/cli/output.ts +185 -0
  41. package/src/cli/run.ts +1110 -0
  42. package/src/compare/index.ts +617 -0
  43. package/src/config/index.ts +275 -0
  44. package/src/config/validate.ts +267 -0
  45. package/src/errors.ts +8 -0
  46. package/src/format.ts +36 -0
  47. package/src/glob.ts +48 -0
  48. package/src/index.ts +62 -0
  49. package/src/ir/cpu.ts +10 -0
  50. package/src/ir/document.ts +471 -0
  51. package/src/ir/fp.ts +31 -0
  52. package/src/ir/git.ts +36 -0
  53. package/src/ir/types.ts +615 -0
  54. package/src/measure/alloc.ts +57 -0
  55. package/src/measure/cpu.ts +99 -0
  56. package/src/measure/environment.ts +41 -0
  57. package/src/measure/inprocess.ts +191 -0
  58. package/src/measure/instructions.ts +133 -0
  59. package/src/measure/loop.ts +57 -0
  60. package/src/measure/noise.ts +55 -0
  61. package/src/measure/paired.ts +312 -0
  62. package/src/measure/peak.ts +202 -0
  63. package/src/measure/timing.ts +263 -0
  64. package/src/profile.ts +109 -0
  65. package/src/renderers/collapsed.ts +35 -0
  66. package/src/renderers/cpu-tree.ts +183 -0
  67. package/src/renderers/cpuprofile.ts +43 -0
  68. package/src/renderers/format.ts +142 -0
  69. package/src/renderers/index.ts +27 -0
  70. package/src/renderers/json.ts +10 -0
  71. package/src/renderers/jsonl.ts +15 -0
  72. package/src/renderers/markdown.ts +525 -0
  73. package/src/renderers/mermaid.ts +78 -0
  74. package/src/renderers/minimal.ts +602 -0
  75. package/src/renderers/paired.ts +229 -0
  76. package/src/renderers/relative.ts +64 -0
  77. package/src/renderers/select.ts +286 -0
  78. package/src/renderers/speedscope.ts +69 -0
  79. package/src/renderers/terminal.ts +466 -0
  80. package/src/renderers/types.ts +27 -0
  81. package/src/spawn/index.ts +396 -0
  82. package/src/stats/bootstrap.ts +153 -0
  83. package/src/stats/index.ts +140 -0
  84. package/src/stats/mannwhitney.ts +81 -0
  85. package/src/time.ts +325 -0
  86. package/src/version.ts +3 -0
  87. package/ab-runner.ts +0 -8
  88. package/chunk-5m601yfv.js +0 -15
  89. package/chunk-82vs1rw1.js +0 -2
  90. package/chunk-dvqggjkn.js +0 -14
  91. package/chunk-fc36fd0b.js +0 -3
  92. package/chunk-pdv5zb3w.js +0 -27
  93. package/chunk-r6hwb84z.js +0 -25
  94. package/cli.js +0 -3
  95. package/index.js +0 -2
  96. package/runner.ts +0 -7
@@ -0,0 +1,218 @@
1
+ # Statistics
2
+
3
+ How ostia samples, summarizes, and decides whether a change is a
4
+ regression.
5
+
6
+ ## Summary statistics
7
+
8
+ Every timing measurement stores its raw samples plus `mean`, `median`,
9
+ `stddev` (population), `min`, `max`, `p25`, `p75`, `p99`,
10
+ `mad` (median absolute deviation) and IQR-based outlier counts
11
+ (mild: beyond 1.5×IQR from the quartiles; severe: beyond 3×IQR).
12
+ Percentiles interpolate linearly between order statistics.
13
+
14
+ Reports lead with the median and show Spread as p75…p99,
15
+ since wall-clock timings have a long right tail that skews the mean
16
+ and standard deviation.
17
+
18
+ ## Sampling
19
+
20
+ ### Subprocess commands (`time`, `ci`)
21
+
22
+ 3 warmup trials, then timed trials until 3s of wall time have passed
23
+ and at least 10 trials have run, unless `samples` sets an exact count.
24
+ With several commands the trials are interleaved round-robin.
25
+ Details: [cli.md](cli.md#sampling).
26
+
27
+ ### In-process tasks (`bench`, `run`)
28
+
29
+ - One untimed first call, then warmup for 10% of the budget.
30
+ Warmup doubles its batch size until a batch takes about 1ms,
31
+ so the loop is hot at the size it will be sampled at.
32
+ - Calls are batched so one trial spans at least 1µs
33
+ (keeping timer resolution out of the reading) and a full budget yields
34
+ about 10,000 trials.
35
+ For batched tasks, five calibration batches settle the per-call
36
+ estimate on their median before sampling starts.
37
+ The reported numbers are per call (`batch` records the batch size).
38
+ - Sampling runs until the budget (default 500ms) is spent
39
+ and the floor is met.
40
+ The budget-driven loop stops at 20,000 trials.
41
+ - The default floor is cost-aware: as many trials as fit in the budget
42
+ (capped at 20), but never below 3 at ≤1ms per trial,
43
+ plus 2 per decade of cost, up to 10.
44
+ See the table in [cli.md](cli.md#sampling-1).
45
+ - Each task runs through its own compiled timing loop.
46
+ A loop shared between tasks lets the JIT specialize its call site for
47
+ whichever task ran first, which made later tasks read slower depending
48
+ on their order in the file.
49
+ - Every result is stored into a ring buffer,
50
+ and `keep()` is available for intermediate values,
51
+ so the JIT can't eliminate the work being measured.
52
+
53
+ Tasks that share a process still share builtin call-site feedback
54
+ and the GC heap.
55
+ For the most comparable numbers, run tasks with `isolate`.
56
+
57
+ ## Noise floor
58
+
59
+ Before measuring, `time()`, `bench()` and `ostia ci` each run a fixed,
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`.
63
+ This is how much this machine's timings vary at the moment,
64
+ independent of the workload.
65
+ `noiseCheck: false` / `--no-noise-check` skips it
66
+ (and the widening below).
67
+
68
+ `time()`, `bench()` and `ostia ci` run the loop again when they finish
69
+ and record how much slower it ran at the end than at the start as
70
+ `environment.noise.driftPct`: the machine's drift over the run
71
+ (thermal throttling, a neighbour on a shared CI runner).
72
+
73
+ A `noisy-machine` warning is added when the 1-minute load average
74
+ exceeds 75% of the available cores.
75
+
76
+ ## Comparing two measurements
77
+
78
+ `compareDocuments` (and `ostia compare`/`ostia ci`) matches workloads by
79
+ id and, for each pair of timing measurements with at least 5 samples on
80
+ each side, runs two tests on the raw samples:
81
+
82
+ - **Bootstrap confidence interval** on the difference of medians.
83
+ Each round resamples both sides with replacement
84
+ and takes the difference of the resampled medians,
85
+ as a percent of the baseline median;
86
+ the 2.5th and 97.5th percentiles over `bootstrapIterations` rounds
87
+ (default 2000) form `ci95`.
88
+ A side with more than 2000 samples is randomly subsampled to 2000
89
+ first, which bounds the cost.
90
+ - **Mann-Whitney U test**, two-sided, tie-corrected,
91
+ normal approximation, reported as `pValue`.
92
+ It tests whether the two distributions differ without assuming
93
+ normality.
94
+
95
+ The bootstrap PRNG is seeded from a hash of the two sample arrays,
96
+ so the same two documents always produce the same interval and verdict.
97
+ The seed is stored in `Comparison.timing.seed`.
98
+
99
+ ### Verdict
100
+
101
+ Let `T = effectiveTimingPct` (below).
102
+
103
+ - `regressed`: `pValue < alpha` and `ci95[0] > T`,
104
+ so the whole interval is above the threshold.
105
+ - `improved`: `pValue < alpha` and `ci95[1] < -T`.
106
+ - `unchanged`: anything else.
107
+
108
+ A large point estimate is not enough.
109
+ For example, `+21.4% median, 95% CI [+5.6%, +23.9%], p=0.023` against
110
+ `T = 10` and `alpha = 0.01` is `unchanged`:
111
+ the interval reaches below the threshold and the p-value is above
112
+ `alpha`.
113
+
114
+ With fewer than 5 samples on either side,
115
+ the tests are skipped and the verdict uses the median change alone
116
+ against `T`; the comparison carries a `thin-comparison` warning
117
+ and has no `ci95`/`pValue`.
118
+
119
+ ### Threshold widening
120
+
121
+ ```
122
+ effectiveTimingPct = max(thresholds.timingPct,
123
+ base.environment.noise.floorPct,
124
+ cand.environment.noise.floorPct)
125
+ + driftPct
126
+
127
+ driftPct = max(|base.environment.noise.driftPct|,
128
+ |cand.environment.noise.driftPct|,
129
+ |candReference / baseReference - 1| × 100)
130
+ ```
131
+
132
+ `candReference` and `baseReference` are each run's average
133
+ reference-loop time (start and end).
134
+ A change smaller than the machine's current jitter is never called a
135
+ regression, and when the machine ran faster or slower for one run than
136
+ the other, every task shifts by about as much,
137
+ so the shift adds to the threshold.
138
+ `driftPct` is `0` for a document without `driftPct`
139
+ (before ostia measured it) beyond the shift between the runs,
140
+ and is left out entirely when either document skipped the noise check.
141
+ The values are stored per comparison (`thresholds.effectiveTimingPct`)
142
+ and in the summary (`effectiveTimingPct`, `driftPct`).
143
+
144
+ Widening trades sensitivity for fewer false alarms:
145
+ on a machine that drifts 10% between two runs,
146
+ a 12% regression reads `unchanged`.
147
+ `ostia ab` pairs base and candidate in one process instead,
148
+ so drift can't favor either side; prefer it for gating pull requests.
149
+
150
+ ### CPU frames and heap types
151
+
152
+ When both sides have CPU evidence, per-frame self-time changes are
153
+ reported; a frame fails the comparison when its self time grows by more
154
+ than `frameSelfPct` and it has at least `minFrameSelfUs` of self time on
155
+ either side.
156
+ When both sides have heap snapshots,
157
+ a heap object type fails when its count grows by more than `heapTypePct`
158
+ (the count only; `retainedBytes` is informational and is never gated).
159
+ These make the comparison's overall `verdict` `"fail"` (exit 1) without
160
+ changing the timing verdict.
161
+ They are plain percentage thresholds, not significance tests:
162
+ each side is a single instrumented run.
163
+
164
+ ### Summary
165
+
166
+ `summary.geomeanPct` is the geometric mean of candidate/base median
167
+ ratios over matched timing comparisons,
168
+ as a signed percent (negative means faster on average).
169
+ `summary.verdict` is `"fail"` when any comparison failed.
170
+
171
+ ## Paired A/B (`ab`)
172
+
173
+ `compareDocuments` compares documents measured at different times,
174
+ so it has to widen its threshold to the noisier side's noise floor.
175
+ `ab()` measures base and candidate in the same process,
176
+ in alternating ~10ms batches, and never compares across time at all:
177
+
178
+ - Each round yields one ratio, candidate time over base time.
179
+ Drift over the run affects both halves of a round alike,
180
+ so it divides out.
181
+ - A task is flagged when the median ratio is past `1 ± thresholdPct/100`
182
+ and the 25th (for a regression) or 75th (for an improvement)
183
+ percentile is on the same side of 1:
184
+ the change held in at least three quarters of rounds.
185
+ No p-value; with 15 rounds, the quartile condition is what keeps a few
186
+ disturbed rounds from flagging a task.
187
+ - A flagged task is re-measured in fresh processes
188
+ (`confirm`, default 2) and counts only when every repeat flags it the
189
+ same way.
190
+ Rounds share one process's JIT decisions,
191
+ and the two sides are separate copies of the code that the JIT
192
+ compiles separately, so one process can consistently favor one side.
193
+ - `geomeanPct` is the geometric mean of the tasks' median ratios
194
+ (for a flagged task, the median over its first run and repeats).
195
+ The run fails when it exceeds `geomeanThresholdPct`,
196
+ which catches a slowdown spread across many tasks.
197
+
198
+ The noise floor is still measured and reported,
199
+ but doesn't widen `thresholdPct`.
200
+
201
+ With `metric: "instructions"`, each round's ratio is candidate over base
202
+ instructions retired per call, counted on the thread running the task
203
+ around each batch, and everything above applies to those ratios instead.
204
+ Pairing cancels drift slower than a round;
205
+ it can't cancel load that changes within one,
206
+ which is where time ratios get their spread on a busy machine.
207
+ Instruction counts don't depend on load,
208
+ so their quartiles stay within about 1% where time's span tens of
209
+ percent; what still moves them is the JIT,
210
+ which is why the quartile rule and confirmation stay.
211
+
212
+ ### Environment mismatch
213
+
214
+ When base and candidate differ in OS, architecture, Bun version,
215
+ or (when both have it) CPU model or core count,
216
+ every comparison carries an `environment-mismatch` warning with the
217
+ differing fields: the delta may reflect the machine rather than the
218
+ code.