ostia 0.2.11 → 0.2.12

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.
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- var rn=`ostia time [flags] <command...>
2
+ var cn=`ostia time [flags] <command...>
3
3
  ostia time [flags] -- <argv...>
4
4
 
5
5
  Time commands as subprocesses. Each <command> is whitespace-split into argv (no shell);
@@ -35,7 +35,7 @@ Examples:
35
35
  ostia time --prepare "rm -rf dist" "bun build.ts"
36
36
  ostia time --time-source "built in (\\d+)ms" "bun build.ts"
37
37
  ostia time -- bun -e "console.log('a b')"
38
- `,Ge=`ostia bench [flags] <suite.ts...>
38
+ `,Ke=`ostia bench [flags] <suite.ts...>
39
39
 
40
40
  Run in-process group()/task() suites, each file in its own child process. With no files,
41
41
  uses ostia.config's "bench" section; each flag overrides its config field.
@@ -72,7 +72,7 @@ Examples:
72
72
  ostia bench bench/*.ts
73
73
  ostia bench bench/*.ts --filter parse --cpu --alloc
74
74
  ostia bench --preload ./bench/dom-setup.ts --bun-flags="--conditions=browser" bench/*.ts
75
- `,Ve=`ostia ab [flags] <suite.ts...>
75
+ `,qe=`ostia ab [flags] <suite.ts...>
76
76
 
77
77
  Pair every task on a git ref's committed tree (base) against the working tree (candidate), in
78
78
  one process, alternating ~10ms batches, and gate on the per-round time ratio. Drift between
@@ -84,6 +84,8 @@ Flags:
84
84
  --base-setup CMD shell command run once in a freshly extracted base tree, e.g. to build
85
85
  gitignored files the suites import (repeatable, in order)
86
86
  --rounds N base/candidate rounds per task (default: 15)
87
+ --metric METRIC judge each round's time or instructions ratio (default: time);
88
+ instructions retired per call barely move on a loaded machine
87
89
  --threshold PCT flag a task whose median ratio moves past PCT (default: 10)
88
90
  --geomean-threshold PCT fail when the geometric mean of all ratios is slower than PCT
89
91
  (default: 1.5)
@@ -97,7 +99,7 @@ Flags:
97
99
  --preload PATH import before each suite file (repeatable, in order)
98
100
  --bun-flags FLAGS extra flags for the bun process running each suite (repeatable)
99
101
  --timeout MS kill a suite (or repeat) process after MS
100
- --out-dir PATH scratch directory and base-tree cache (default: node_modules/.cache/ostia)
102
+ --out-dir PATH scratch directory (default: node_modules/.cache/ostia)
101
103
  --keep-trees N base trees to keep cached, least recently used go first (default: 5)
102
104
  --clean remove every cached base tree, then exit
103
105
  --config PATH read this config file instead of ostia.config.ts/.json
@@ -109,10 +111,11 @@ Flags:
109
111
  --quiet don't print the report
110
112
  --help show this message
111
113
 
112
- The base tree is cached per commit (and --base-setup commands) under --out-dir. Setup runs
114
+ The base tree is cached per commit (and --base-setup commands) under .ostia/ab. Setup runs
113
115
  with the project's node_modules linked in, and OSTIA_AB_SHA and OSTIA_AB_CANDIDATE_DIR (the
114
- working tree) set. A flagged task counts only when every fresh-process repeat flags it the
115
- same way. A task that throws isn't timed; one that throws on the candidate side only fails
116
+ working tree) set. Instructions per call are counted where the machine allows (macOS;
117
+ Linux with perf_event_paranoid <= 2 and a hardware counter) and shown next to time. A
118
+ flagged task counts only when every fresh-process repeat flags it the same way. A task that throws isn't timed; one that throws on the candidate side only fails
116
119
  the run. A task whose suite file and output both changed reads "not comparable" and stays
117
120
  out of the verdict. Exit codes: 0 pass, 1 a confirmed regression, a candidate-only throw,
118
121
  the geomean over its threshold or a memory regression, 2 nothing paired or a harness error (not a git repo,
@@ -122,9 +125,10 @@ Examples:
122
125
  ostia ab bench/parse.bench.ts
123
126
  ostia ab bench/*.ts --base origin/main --rounds 21
124
127
  ostia ab bench/*.ts --filter parse --format minimal
128
+ ostia ab bench/*.ts --metric instructions --threshold 3
125
129
  ostia ab bench/*.ts --base-setup "bun scripts/generate.ts"
126
130
  ostia ab bench/paint.bench.ts --alloc --peak-mem
127
- `,Je=`ostia compare <base.json> <candidate.json>
131
+ `,Ye=`ostia compare <base.json> <candidate.json>
128
132
  ostia compare <candidate.json> --baseline <base.json>
129
133
 
130
134
  Compare two ProfileDocuments by workload id (or a task's former names, from its
@@ -142,7 +146,7 @@ Flags:
142
146
 
143
147
  Exactly two document paths (one with --baseline); anything more is an error.
144
148
  Exit codes: 0 pass, 1 a workload regressed, 2 nothing matched or a harness error.
145
- `,ze=`ostia report <document.json> [flags]
149
+ `,Ze=`ostia report <document.json> [flags]
146
150
 
147
151
  Render a saved ProfileDocument. Files, not a GUI for the visualization formats -
148
152
  hand the output to speedscope.app, flamegraph.pl, or a Mermaid renderer.
@@ -170,7 +174,7 @@ Examples:
170
174
  ostia report doc.json --format markdown
171
175
  ostia report doc.json --format speedscope --out-dir node_modules/.cache/ostia/viz
172
176
  ostia report doc.json --format collapsed | flamegraph.pl > flame.svg
173
- `,on=`ostia ci [flags]
177
+ `,un=`ostia ci [flags]
174
178
 
175
179
  Run ostia.config's workloads (reusing cached runs whose declared inputs are unchanged),
176
180
  compare against a saved baseline, and gate on regressions.
@@ -190,7 +194,7 @@ Flags:
190
194
  Exit codes: 0 pass, 1 regression, 2 harness error (missing config/baseline, a workload
191
195
  failed or produced no samples, or an onMissingBaseline "fail" mismatch), 130 Ctrl-C (the
192
196
  partial document is exported; nothing is compared or saved).
193
- `,ee=`ostia baseline <save|list|show> [args]
197
+ `,re=`ostia baseline <save|list|show> [args]
194
198
 
195
199
  Manage the baseline ProfileDocuments "ostia ci" gates against and "ostia compare --baseline"
196
200
  reads.
@@ -213,7 +217,7 @@ Examples:
213
217
  ostia baseline list
214
218
  ostia baseline show main
215
219
  ostia baseline show main --format markdown
216
- `,sn=`ostia - profiling and benchmarking for Bun
220
+ `,mn=`ostia - profiling and benchmarking for Bun
217
221
 
218
222
  Commands:
219
223
  time Time commands N times and report timing/CPU/heap
@@ -226,4 +230,4 @@ Commands:
226
230
 
227
231
  Run "ostia <command> --help" for details.
228
232
  `;
229
- export{rn,Ge,Ve,Je,ze,on,ee,sn};
233
+ export{cn,Ke,qe,Ye,Ze,un,re,mn};
@@ -0,0 +1,14 @@
1
+ // @bun
2
+ import{V}from"./chunk-1g1x9zz2.js";import{dlopen as g,FFIType as l,ptr as B}from"bun:ffi";import{heapStats as S}from"bun:jsc";function J(){let{heapSize:n,extraMemorySize:e}=S(),s=process.memoryUsage.rss();return{rssBytes:s,residentBytes:h()??s,liveBytes:n+e}}function h(){if(process.platform!=="darwin")return;return u??=b(),u()}var u;function b(){let{symbols:n}=g("/usr/lib/libSystem.B.dylib",{proc_pid_rusage:{args:[l.i32,l.i32,l.ptr],returns:l.i32}}),e=new BigUint64Array(12);return()=>n.proc_pid_rusage(process.pid,0,B(e))===0?Number(e[8]):void 0}var t={ready:1,go:2,sampling:3,stop:4},A=`self.onmessage = (event) => {
3
+ const slots = new Int32Array(event.data)
4
+ Atomics.store(slots, 0, ${t.ready})
5
+ Atomics.wait(slots, 0, ${t.ready})
6
+ if (Atomics.compareExchange(slots, 0, ${t.go}, ${t.sampling}) === ${t.go}) {
7
+ while (Atomics.load(slots, 0) === ${t.sampling}) {
8
+ const kib = (process.memoryUsage.rss() / 1024) | 0
9
+ if (kib > Atomics.load(slots, 1)) Atomics.store(slots, 1, kib)
10
+ }
11
+ }
12
+ postMessage(0)
13
+ }`,y=1e4;async function z(n=A){let e=new Int32Array(new SharedArrayBuffer(8)),s=new Worker(URL.createObjectURL(new Blob([n],{type:"application/javascript"}))),a=new Promise((r,c)=>{let o=(m)=>c(Error(`RSS sampler worker failed: ${m}`));s.onerror=(m)=>o(m.message||"uncaught error"),s.addEventListener("close",()=>o("worker exited unexpectedly"))});a.catch(()=>{});let i=new Promise((r)=>{s.onmessage=r});try{s.postMessage(e.buffer);let r=Date.now()+y;while(Atomics.load(e,0)!==t.ready){if(Date.now()>r)throw Error("RSS sampler worker failed: did not start in time");await Promise.race([Bun.sleep(1),a])}}catch(r){throw s.terminate(),r}return{async during(r){try{Atomics.store(e,0,t.go),Atomics.notify(e,0);let c=Bun.nanoseconds()+50000000;while(Atomics.load(e,0)!==t.sampling&&Bun.nanoseconds()<c);let o=Date.now()+y;while(Atomics.load(e,0)!==t.sampling){if(Date.now()>o)throw Error("RSS sampler worker failed: did not start sampling");await Promise.race([Bun.sleep(1),a])}return await r(),Atomics.store(e,0,t.stop),await Promise.race([i,a]),Atomics.load(e,1)*1024}finally{s.terminate()}}}}async function se(n,e,s){let a=s??await z();Bun.gc(!0);let i=J(),r=process.resourceUsage().maxRSS*1024,c=Bun.nanoseconds(),o=0,m=await a.during(async()=>{let p=n();if(V(p))await p;o=Bun.nanoseconds()-c}),d=process.resourceUsage().maxRSS*1024,w=Math.max(m,d>r?d:0),f=e?i.residentBytes-e.residentBytes-(i.liveBytes-e.liveBytes):0;return{peakBytes:Math.max(0,w-i.rssBytes),slackBytes:Math.max(0,f),wallNs:o}}
14
+ export{J,z,se};
package/cli.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var t=process.argv[2];if(t===void 0||t==="--help"||t==="-h"){let{MAIN_HELP:i}=await import("./chunk-82vs1rw1.js");await Bun.write(Bun.stdout,i),process.exit(t===void 0?2:0)}var{main:e}=await import("./chunk-r6hwb84z.js");process.exit(await e());
3
+ var t=process.argv[2];if(t===void 0||t==="--help"||t==="-h"){let{MAIN_HELP:i}=await import("./chunk-4esjfc2m.js");await Bun.write(Bun.stdout,i),process.exit(t===void 0?2:0)}var{main:e}=await import("./chunk-468h5412.js");process.exit(await e());
package/index.d.ts CHANGED
@@ -25,11 +25,29 @@ export interface WorkloadConfig {
25
25
  ignoreExitCodes?: number[];
26
26
  }
27
27
 
28
+ export interface BenchProject {
29
+ /** Globs against the current directory. A suite file takes the first
30
+ * project one of these matches; `ostia bench` with no files also runs
31
+ * every file they expand to. */
32
+ suites: string[];
33
+ /** Replaces the top-level `preload` for these files; `[]` runs them with
34
+ * none. Unset: the top-level list applies. */
35
+ preload?: string[];
36
+ /** Replaces the top-level `bunFlags` for these files, as `preload` does. */
37
+ bunFlags?: string[];
38
+ }
39
+
28
40
  interface BenchConfig {
29
41
  /** Suite file globs, resolved against the config's directory (e.g.
30
42
  * "bench/**\/*.bench.ts"). Suite files given on the command line replace
31
43
  * this list. */
32
44
  suites?: string[];
45
+ /** Per-suite `preload`/`bunFlags`, so one tier (e.g. DOM-dependent suites)
46
+ * can pay for a setup the others don't need. The first project whose
47
+ * `suites` match a file wins; a file no project matches gets the top-level
48
+ * `preload`/`bunFlags`. `--preload` / `--bun-flags` replace the matching
49
+ * field for every file. */
50
+ projects?: BenchProject[];
33
51
  preload?: string[];
34
52
  /** Extra flags for the `bun` process that runs each suite file; see
35
53
  * `BenchOptions.bunFlags`. `--bun-flags` replaces this list. */
@@ -59,6 +77,9 @@ export interface AbConfig {
59
77
  /** Base trees to keep cached; see `AbOptions.keepTrees`. `--keep-trees`
60
78
  * overrides. Default: 5. */
61
79
  keepTrees?: number;
80
+ /** Judge rounds by `"time"` or `"instructions"`; see `AbOptions.metric`.
81
+ * `--metric` overrides. Default: `"time"`. */
82
+ metric?: "time" | "instructions";
62
83
  /** Compare retained heap per call; see `AbOptions.alloc`. `--alloc` /
63
84
  * `--no-alloc` override. `bench.alloc` doesn't apply to `ab`. */
64
85
  alloc?: boolean;
@@ -253,6 +274,9 @@ interface Measurement {
253
274
  heap?: HeapEvidence;
254
275
  memory?: MemoryEvidence;
255
276
  jit?: JitTierBreakdown;
277
+ /** In-process timing, where the machine counts them: instructions the
278
+ * task retired per call, one sample per trial (see `InstructionStats`). */
279
+ instructions?: InstructionStats;
256
280
  /** `phase: "paired"` only; `timing` is then the candidate side. */
257
281
  paired?: PairedEvidence;
258
282
  /** `phase: "paired"` only: the task threw on one side or both
@@ -315,6 +339,11 @@ interface TimingStats {
315
339
  batch?: number;
316
340
  }
317
341
 
342
+ interface InstructionStats {
343
+ samples: number[];
344
+ median: number;
345
+ }
346
+
318
347
  interface Frame {
319
348
  key: string;
320
349
  name: string;
@@ -409,14 +438,23 @@ interface PairedEvidence {
409
438
  /** 25th/75th percentile of `ratios`. */
410
439
  ratioP25: number;
411
440
  ratioP75: number;
412
- /** Median ratio past `1 ± threshold` and on the same side of 1 in at least
413
- * three quarters of rounds. */
441
+ /** Instructions retired per call on each side, where the machine counts
442
+ * them; what `AbSummary.metric: "instructions"` judges. */
443
+ instructions?: PairedInstructions;
444
+ /** `AbSummary.metric`'s median ratio past `1 ± threshold` and on the same
445
+ * side of 1 in at least three quarters of rounds. */
414
446
  flagged?: "regressed" | "improved";
415
- /** Each fresh-process re-measurement of a flagged workload. */
447
+ /** Each fresh-process re-measurement of a flagged workload; `flagged` by
448
+ * `AbSummary.metric`. */
416
449
  repeats?: {
417
450
  medianRatio: number;
418
451
  ratioP25: number;
419
452
  ratioP75: number;
453
+ instructions?: {
454
+ medianRatio: number;
455
+ ratioP25: number;
456
+ ratioP75: number;
457
+ };
420
458
  flagged?: "regressed" | "improved";
421
459
  }[];
422
460
  /** Set when `flagged` is: whether every repeat flagged the same way. */
@@ -439,6 +477,19 @@ interface PairedEvidence {
439
477
  peak?: MemoryChange;
440
478
  }
441
479
 
480
+ interface PairedInstructions {
481
+ /** Per round, index-aligned with `PairedEvidence.baseSamples`. */
482
+ baseSamples: number[];
483
+ candSamples: number[];
484
+ baseMedian: number;
485
+ candMedian: number;
486
+ /** Candidate/base instructions per round. */
487
+ ratios: number[];
488
+ medianRatio: number;
489
+ ratioP25: number;
490
+ ratioP75: number;
491
+ }
492
+
442
493
  interface MemoryChange {
443
494
  baseBytes: number;
444
495
  candBytes: number;
@@ -460,6 +511,9 @@ interface AbSummary {
460
511
  * are all candidate-only. */
461
512
  newSuites?: string[];
462
513
  rounds: number;
514
+ /** What verdicts, confirmation and `geomeanPct` judge: each round's time
515
+ * ratio, or its instruction ratio (`PairedEvidence.instructions`). */
516
+ metric: "time" | "instructions";
463
517
  thresholdPct: number;
464
518
  geomeanThresholdPct: number;
465
519
  /** Workloads measured on both sides. */
@@ -487,9 +541,9 @@ interface AbSummary {
487
541
  regressed: number;
488
542
  improved: number;
489
543
  };
490
- /** Geometric mean of the workloads' median ratios, signed percent (negative:
491
- * candidate faster); a flagged workload contributes its median over its main
492
- * run and repeats. `null` when nothing was paired. */
544
+ /** Geometric mean of the workloads' median `metric` ratios, signed
545
+ * percent (negative: candidate faster); a flagged workload contributes its
546
+ * median over its main run and repeats. `null` when nothing was paired. */
493
547
  geomeanPct: number | null;
494
548
  /** `"fail"` when any workload regressed (confirmed), threw on the
495
549
  * candidate side only, or `geomeanPct` exceeds `geomeanThresholdPct`, or
@@ -682,6 +736,13 @@ export interface AbOptions {
682
736
  /** Rounds per workload, each one base batch and one candidate batch of
683
737
  * about 10ms (default: 15). */
684
738
  rounds?: number;
739
+ /** What to judge each round by: the candidate/base time ratio
740
+ * (`"time"`, the default), or the ratio of instructions each side retired
741
+ * per call (`"instructions"`), which a loaded machine barely moves, so a
742
+ * lower `thresholdPct` holds. Instructions are recorded either way where
743
+ * the machine counts them (see `PairedEvidence.instructions`); asking to
744
+ * judge by them where it can't throws an `OstiaUsageError`. */
745
+ metric?: "time" | "instructions";
685
746
  /** Flag a workload whose median candidate/base ratio moves past this many
686
747
  * percent (default: 10). */
687
748
  thresholdPct?: number;
@@ -695,6 +756,8 @@ export interface AbOptions {
695
756
  filter?: string;
696
757
  preload?: string[];
697
758
  bunFlags?: string[];
759
+ /** Per-suite `preload` / `bunFlags`; see `BenchOptions.projects`. */
760
+ projects?: BenchProject[];
698
761
  outDir?: string;
699
762
  cwd?: string;
700
763
  noiseCheck?: boolean;
@@ -715,7 +778,7 @@ export interface AbOptions {
715
778
  * `OSTIA_AB_SHA` / `OSTIA_AB_CANDIDATE_DIR` (the working tree's `cwd`) in
716
779
  * its environment. The tree is cached per commit and command list. */
717
780
  baseSetup?: string | string[];
718
- /** Base trees to keep under `<outDir>/ab`, counting this run's: after a
781
+ /** Base trees to keep under `.ostia/ab`, counting this run's: after a
719
782
  * run, older ones go, least recently used first, unless one was used in
720
783
  * the last hour (another run may still need it). Default: 5. */
721
784
  keepTrees?: number;
@@ -794,6 +857,12 @@ export interface BenchOptions {
794
857
  /** Extra flags for the `bun` invocation that runs each suite file (e.g.
795
858
  * `["--conditions", "browser"]`), placed before the runner script path. */
796
859
  bunFlags?: string[];
860
+ /** Per-suite `preload` / `bunFlags`: the first project whose `suites` globs
861
+ * match a suite file (by its path relative to `cwd`) replaces those two
862
+ * fields for that file, so suites that need no setup don't pay for the
863
+ * others'. A field a project leaves unset keeps the top-level value above;
864
+ * `[]` clears it. */
865
+ projects?: BenchProject[];
797
866
  /** Measure this machine's noise floor once, before any suite runs
798
867
  * (default: true), and stamp it on the document as `environment`. */
799
868
  noiseCheck?: boolean;
@@ -1089,8 +1158,16 @@ interface MinimalPaired {
1089
1158
  /** What the first process saw, before confirmation. */
1090
1159
  flagged?: "regressed" | "improved";
1091
1160
  confirmed?: boolean;
1092
- /** Median ratio of each fresh-process repeat. */
1161
+ /** Median ratio of each fresh-process repeat, by the summary's `metric`. */
1093
1162
  repeats?: number[];
1163
+ /** Where the machine counts them: the base's median instructions per call
1164
+ * and the candidate/base instruction ratios. */
1165
+ instructions?: {
1166
+ baseMedian: number;
1167
+ medianRatio: number;
1168
+ ratioP25: number;
1169
+ ratioP75: number;
1170
+ };
1094
1171
  sameOutput: boolean;
1095
1172
  /** The suite file differs from the base's copy. */
1096
1173
  suiteChanged?: true;
@@ -1144,6 +1221,9 @@ interface MinimalRunLine {
1144
1221
  retainedBytesPerOp?: number;
1145
1222
  /** `--peak-mem`: how far the task's first call raised RSS, bytes. */
1146
1223
  peakBytes?: number;
1224
+ /** In-process tasks, where the machine counts them: median instructions
1225
+ * retired per call (`ab`: the candidate's). */
1226
+ instructions?: number;
1147
1227
  /** Median over the group's reference median (its baseline task, else its
1148
1228
  * fastest); only when the document has more than one timing run. */
1149
1229
  relative?: number;
@@ -1203,6 +1283,9 @@ interface MinimalSummaryLine {
1203
1283
  ref: string;
1204
1284
  sha: string;
1205
1285
  };
1286
+ /** `ab` only: what the verdicts and `geomeanPct` judge, each round's time
1287
+ * or instruction ratio. */
1288
+ metric?: "time" | "instructions";
1206
1289
  /** `ab` only: the gate on `geomeanPct`. */
1207
1290
  geomeanThresholdPct?: number;
1208
1291
  /** `ab` only: flagged in the first process but not reproduced; counted in `unchanged`. */
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{x,fe,_,V,J,he,K,be,bn,M,h,wn,yn,kn,Pn}from"./chunk-pdv5zb3w.js";import"./chunk-fc36fd0b.js";import{r,u,E,a,xn,Mn,Tn}from"./chunk-5m601yfv.js";export{_ as AbBaseError,J as AbSetupError,V as AbSuiteError,x as DEFAULT_THRESHOLDS,M as MINIMAL_PROTOCOL_VERSION,E as OstiaDocumentError,he as ab,K as bench,fe as compareDocuments,r as createDocument,Pn as defineConfig,xn as group,Tn as keep,a as loadDocument,kn as profile,bn as range,h as renderers,wn as run,u as saveDocument,yn as sweep,Mn as task,be as time};
2
+ import{M,we,L,K,q,ke,Z,Pe,Pn,R,b,xn,Mn,Rn,Tn}from"./chunk-05jfst35.js";import"./chunk-23g2rwrn.js";import{s,p,N,a,Sn,vn,Cn}from"./chunk-1g1x9zz2.js";export{L as AbBaseError,q as AbSetupError,K as AbSuiteError,M as DEFAULT_THRESHOLDS,R as MINIMAL_PROTOCOL_VERSION,N as OstiaDocumentError,ke as ab,Z as bench,we as compareDocuments,s as createDocument,Tn as defineConfig,Sn as group,Cn as keep,a as loadDocument,Rn as profile,Pn as range,b as renderers,xn as run,p as saveDocument,Mn as sweep,vn as task,Pe as time};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ostia",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Fast profiling and benchmarking for Bun.",
5
5
  "type": "module",
6
6
  "engines": {
package/runner.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{u,D,ue,nn,de,g,B,U,pe}from"./chunk-5m601yfv.js";import{H,G,ne}from"./chunk-dvqggjkn.js";async function c(){let[r,o,i]=process.argv.slice(2);if(!r||!o)return process.stderr.write(`bench runner: usage: runner.ts <suiteFile> <outputPath> [optsJson]
4
- `),2;let t=i?JSON.parse(i):{},p,l;if(t.peakMemFor)l=await G(),await import("./index.js"),p=H();for(let e of t.preload??[])await import(e);ue(),await import(r);let d=D();if(d.length===0)return process.stderr.write(`bench runner: ${r} registered no tasks (no task() calls found).
5
- `),2;let a;try{a=B(d,t.filter,r,!t.workloadIds&&!t.peakMemFor)}catch(e){return process.stderr.write(`bench runner: ${e.message}
6
- `),2}let n=(e)=>U(r,e).id;if(t.workloadIds){let e=new Set(t.workloadIds);a=a.filter((s)=>e.has(n(s)))}if(t.peakMemFor){let e=a.find((f)=>n(f)===t.peakMemFor);if(!e)return process.stderr.write(`bench runner: no task with workload id ${t.peakMemFor} in ${r}.
7
- `),2;await g(e,"before"),await e.opts?.before?.();let s=await ne(e.fn,p,l);return await e.opts?.after?.(),await g(e,"after"),await Bun.write(o,JSON.stringify(s)),0}if(t.planPath){let e=a.map((s)=>({workloadId:n(s),isolate:nn(s,t.isolate??!1),peakMem:!s.skipped&&de(s,t.peakMem??!1)}));await Bun.write(t.planPath,JSON.stringify({tasks:e}))}let k=t.workloadIds?a:a.filter((e)=>!nn(e,t.isolate??!1)),m=await pe(r,k,t);return await u(m,o),0}c().then((r)=>process.exit(r));
3
+ import{p,pe,B,fe,on,ge,h,U,W,be}from"./chunk-1g1x9zz2.js";import{J,z,se}from"./chunk-ct2xsezd.js";async function c(){let[r,o,i]=process.argv.slice(2);if(!r||!o)return process.stderr.write(`bench runner: usage: runner.ts <suiteFile> <outputPath> [optsJson]
4
+ `),2;let t=i?JSON.parse(i):{},l,d;if(t.peakMemFor)d=await z(),await import("./index.js"),l=J();for(let e of t.preload??[])await import(e);fe(),await import(r);let u=B();if(u.length===0)return process.stderr.write(`bench runner: ${r} registered no tasks (no task() calls found).${pe}
5
+ `),2;let a;try{a=U(u,t.filter,r,!t.workloadIds&&!t.peakMemFor)}catch(e){return process.stderr.write(`bench runner: ${e.message}
6
+ `),2}let n=(e)=>W(r,e).id;if(t.workloadIds){let e=new Set(t.workloadIds);a=a.filter((s)=>e.has(n(s)))}if(t.peakMemFor){let e=a.find((f)=>n(f)===t.peakMemFor);if(!e)return process.stderr.write(`bench runner: no task with workload id ${t.peakMemFor} in ${r}.
7
+ `),2;await h(e,"before"),await e.opts?.before?.();let s=await se(e.fn,l,d);return await e.opts?.after?.(),await h(e,"after"),await Bun.write(o,JSON.stringify(s)),0}if(t.planPath){let e=a.map((s)=>({workloadId:n(s),isolate:on(s,t.isolate??!1),peakMem:!s.skipped&&ge(s,t.peakMem??!1)}));await Bun.write(t.planPath,JSON.stringify({tasks:e}))}let k=t.workloadIds?a:a.filter((e)=>!on(e,t.isolate??!1)),m=await be(r,k,t);return await p(m,o),0}c().then((r)=>process.exit(r));
package/chunk-5m601yfv.js DELETED
@@ -1,15 +0,0 @@
1
- // @bun
2
- import{statSync as ht}from"fs";import{rm as kt}from"fs/promises";import{isAbsolute as yt}from"path";function T(d){return d instanceof Error?d.message:String(d)}class l extends Error{}import{rename as it,rm as st}from"fs/promises";import{isAbsolute as at,relative as ut}from"path";class on extends Error{}var Rn=new WeakMap;function vn(d){if(typeof d.pattern!=="string")return d.pattern;let h=Rn.get(d);if(!h)h=new RegExp(d.pattern),Rn.set(d,h);return h}function we(d){let h=vn(d);if(/[gyd]/.test(h.flags))throw RangeError("timeSource pattern must not use the g, y or d flag")}var qn={ns:1,us:1000,ms:1e6,s:1e9};function qe(d,h){let y=d!==void 0?AbortSignal.timeout(d):void 0,x=y&&h?AbortSignal.any([y,h]):y??h;return{spawn:x?{signal:x,killSignal:"SIGKILL"}:{},timedOut:()=>y?.aborted??!1}}async function ln(d){let h=d.timeSource!==void 0,y=Bun.nanoseconds(),x=qe(d.timeoutMs,d.signal),M=Bun.spawn(d.argv,{cwd:d.cwd,env:d.env,stdout:h?"pipe":"ignore",stderr:h?"pipe":"ignore",stdin:"ignore",...x.spawn}),A=h?Promise.all([new Response(M.stdout).text(),new Response(M.stderr).text()]):void 0,I=await M.exited,G=Bun.nanoseconds(),_=M.resourceUsage?.(),J=x.timedOut(),H={wallNs:G-y,exitCode:J?null:I,userNs:_?Number(_.cpuTime.user)*1000:void 0,systemNs:_?Number(_.cpuTime.system)*1000:void 0,maxRssBytes:_?.maxRSS,...J&&{timedOut:!0}};if(A){let[ne,oe]=await A;if(d.timeSource&&!J)try{H.reportedNs=Yn(d.timeSource,ne,oe,d.argv)}catch(be){if(!(be instanceof on))throw be;H.timeSourceNoMatch=!0,H.timeSourceMissOutput=Zn(ne,oe)}}return H}function Yn(d,h,y,x=[]){let M=vn(d),A=d.group??1,I=M.exec(h)??M.exec(y),G=x.length>0?` for "${x.join(" ")}"`:"";if(!I)throw new on(`timeSource pattern ${M} did not match the output${G}. Output was:
3
- ${Pn(h,y)}`);let _=I[A];if(_===void 0)throw Error(`timeSource pattern ${M} matched${G} but has no capture group ${A} (matched text: "${I[0]}").`);let J=Number(_);if(!Number.isFinite(J))throw Error(`timeSource pattern ${M} group ${A} captured "${_}"${G}, which is not a number.`);return J*qn[d.unit??"ms"]}function Pn(d,h){let x=(A)=>A.length>800?`${A.slice(0,800)}\u2026(${A.length-800} more)`:A,M=[];if(d.trim())M.push(`--- stdout ---
4
- ${x(d.trimEnd())}`);if(h.trim())M.push(`--- stderr ---
5
- ${x(h.trimEnd())}`);return M.length>0?M.join(`
6
- `):"(empty)"}var rn=2048;function Zn(d,h){let y=Pn(d,h);if(Buffer.byteLength(y,"utf8")<=rn)return y;let x=y.slice(0,rn);while(Buffer.byteLength(x,"utf8")>rn)x=x.slice(0,-1);return`${x}\u2026`}var Xn=1048576;async function Qn(d,h=Xn){let y=Math.floor(h/2),x=d.getReader(),M=[],A=0,I=[],G=0,_=0;try{for(;;){let{done:be,value:ee}=await x.read();if(be)break;if(!ee||ee.byteLength===0)continue;_+=ee.byteLength;let re=ee;if(A<y){let te=y-A;if(re.byteLength<=te){M.push(re),A+=re.byteLength;continue}M.push(re.subarray(0,te)),A+=te,re=re.subarray(te)}I.push(re),G+=re.byteLength;while(G>y&&I.length>0){let te=I[0],se=G-y;if(te.byteLength<=se)I.shift(),G-=te.byteLength;else I[0]=te.subarray(se),G-=se}}}finally{x.releaseLock()}let J=new TextDecoder,H=J.decode(Buffer.concat(M));if(_<=A+G)return H;let ne=J.decode(Buffer.concat(I)),oe=_-A-G;return`${H}
7
- \u2026(${oe} bytes elided)\u2026
8
- ${ne}`}async function ye(d,h,y){if(typeof d==="function"){await d(h);return}let x=sn(d),M=qe(y.timeoutMs,y.signal),A=Bun.spawn(x,{cwd:y.cwd,env:y.env,stdout:"ignore",stderr:"pipe",stdin:"ignore",...M.spawn}),I=Qn(A.stderr).catch(()=>""),G=await A.exited,_=M.timedOut();if(!_&&y.signal?.aborted)return;if(!_&&G===0)return;let J=_?`timed out after ${y.timeoutMs}ms`:`exited with code ${G}`,H=(await I).trim();throw Error(`prepare command "${x.join(" ")}" ${J} before ${h.phase} trial ${h.index}.${H?`
9
- ${H}`:""}`)}function sn(d){if(d===void 0||typeof d==="function")return;return Array.isArray(d)?d:q(d)}function En(d){if(d===void 0)return;return{pattern:typeof d.pattern==="string"?d.pattern:d.pattern.source,...d.group!==void 0&&{group:d.group},...d.unit!==void 0&&{unit:d.unit}}}function q(d){return d.trim().split(/\s+/).filter(Boolean)}var et={ns:1,\u{b5}s:1000,ms:1e6,s:1e9};function R(d){let h=Math.abs(d);if(h>=1e9)return"s";if(h>=1e6)return"ms";if(h>=1000)return"\xB5s";return"ns"}function nt(d){let h=Math.floor(Math.log10(Math.max(Math.abs(d),1)))+1;return Math.max(1,3-h)}function e(d,h=R(d)){let y=d/et[h];return`${y.toFixed(nt(y))} ${h}`}function c(d){if(d.length===0)throw Error("computeTimingStats: samples must be non-empty");let h=d.length,y=k(d),x=0;for(let V=0;V<h;V++)x+=d[V];let M=x/h,A=o(y,0.5),I=0;for(let V=0;V<h;V++){let ie=d[V]-M;I+=ie*ie}let G=Math.sqrt(I/h),_=y[0],J=y[h-1],H=o(y,0.25),ne=o(y,0.75),oe=ne-H,be=H-1.5*oe,ee=ne+1.5*oe,re=H-3*oe,te=ne+3*oe,se=0,fe=0;for(let V=0;V<h;V++){let ie=d[V];if(ie<re||ie>te)fe++;else if(ie<be||ie>ee)se++}let he=o(y,0.99),K=new Float64Array(h);for(let V=0;V<h;V++)K[V]=Math.abs(d[V]-A);K.sort();let z=o(K,0.5);return{unit:"ns",samples:d,mean:M,median:A,stddev:G,min:_,max:J,outliers:{mild:se,severe:fe},p25:H,p75:ne,p99:he,mad:z}}function k(d){let h=new Float64Array(d.length);return h.set(d),h.sort(),h}function o(d,h){let y=d.length;if(y===1)return d[0];let x=h*(y-1),M=Math.floor(x),A=Math.ceil(x);if(M===A)return d[M];let I=x-M;return d[M]*(1-I)+d[A]*I}var tt=5000000;function ke(d,h,y="subprocess",x=[]){let M=[],A=d.samples[0];if(A!==void 0){let _=d.p75-d.p25;if(A>d.median+3*_&&A>2*d.median&&_>0)M.push({code:"slow-first-run",message:`First run took ${e(A)}, much slower than the median ${e(d.median)}. Consider more warmup.`,data:{firstNs:A,medianNs:d.median}})}if(y!=="inprocess"&&d.outliers.mild+d.outliers.severe>0)M.push({code:"outliers-detected",message:`${d.outliers.mild+d.outliers.severe} outlier(s) detected (${d.outliers.severe} severe, ${d.outliers.mild} mild).`,data:d.outliers});if(y==="subprocess"&&d.median<tt)M.push({code:"fast-command",message:`Median run time (${(d.median/1e6).toFixed(3)}ms) is very fast; results may be dominated by spawn overhead.`,data:{medianNs:d.median}});let I=new Set(x),G=h.filter((_)=>_!==void 0&&_!==0&&!I.has(_));if(G.length>0)M.push({code:"nonzero-exit",message:`${G.length} of ${h.length} trial(s) exited non-zero.`,data:{exitCodes:G}});return M}var Nn={name:"ostia",version:"0.2.11",description:"Fast profiling and benchmarking for Bun.",type:"module",engines:{bun:">=1.4.0"},exports:{".":"./src/index.ts"},bin:{ostia:"src/cli/main.ts"},scripts:{build:"bun scripts/build.ts","smoke:package":"bun scripts/smoke-package.ts",test:"bun test",typecheck:"bun check","typecheck:package":"bun check -p tests/types",lint:"biome check .","lint:fix":"biome check --write . --unsafe","lint:changed":"biome check --changed --no-errors-on-unmatched .","lint:fix:changed":"biome check --write --unsafe --changed --no-errors-on-unmatched .",knip:"knip-bun",bench:"bun src/cli/main.ts bench bench/*.ts","bench:baseline":"bun src/cli/main.ts bench bench/*.ts --budget 3000 --min-samples 30 --export-json .ostia/baselines/bench-main.json",baseline:"bun src/cli/main.ts baseline save",dogfood:"bun test && bun src/cli/main.ts ci",examples:"bun scripts/run-examples.ts"},devDependencies:{"@biomejs/biome":"2.5.14","@types/bun":"^1.4.2",knip:"^6.38.0",typescript:"npm:@typescript/typescript6@^6.0.2"},repository:{type:"git",url:"git+https://github.com/metonym/ostia.git"}};var ae=Nn.version;function S(d,h){return JSON.stringify(an(d),null,h)}function an(d){if(Array.isArray(d))return d.some((y)=>y!==null&&typeof y==="object")?d.map(an):d;if(d!==null&&typeof d==="object"){let h=d,y={};for(let x of Object.keys(h).sort())y[x]=an(h[x]);return y}return d}function n(d,...h){let y=Bun.CryptoHasher.hash("sha256",S(h),"hex");return`${d}_${y.slice(0,16)}`}var Fn;function un(d){let h=Bun.spawnSync(["git",...d],{timeout:200,stdout:"pipe",stderr:"ignore"});return h.success?h.stdout.toString().trim():void 0}function ot(){try{let d=un(["rev-parse","--short","HEAD"]);if(d===void 0)return;return{sha:d,branch:un(["rev-parse","--abbrev-ref","HEAD"])??"HEAD",dirty:(un(["status","--porcelain"])?.length??0)>0}}catch{return}}function An(){return Fn??={git:ot()},Fn.git}function Ve(d){return Object.fromEntries(Object.entries(d).filter(([,h])=>h!==void 0))}function cn(d,h,y){return n("run",d,h,y,Bun.version,ae)}function r(d,h,y){let x=An();return{schemaVersion:2,toolVersion:ae,bunVersion:Bun.version,platform:{os:process.platform,arch:process.arch},createdAt:new Date().toISOString(),workloads:d,measurements:h,...Ve({environment:y,git:x})}}function me(d,h,y={}){if(y.timeSource)we(y.timeSource);let x=sn(y.prepare),M=En(y.timeSource),A=typeof y.prepare==="function"?y.prepare.toString():x;return{id:n("wl","subprocess",d,...A!==void 0||M!==void 0?[A??null,M??null]:[]),kind:"subprocess",command:d,label:h,...Ve({prepare:x,timeSource:M})}}function pn(d,h){return{id:h===void 0?n("wl","inprocess",d.name,d.toString()):n("wl","inprocess-named",h),kind:"inprocess",label:h}}function mn(d,h,y={}){let x=at(d)?ut(process.cwd(),d):d,M=y.params!==void 0?n("wl","inprocess-entry",x,h,y.params):n("wl","inprocess-entry",x,h),{group:A,...I}=y;return{id:M,kind:"inprocess",entry:{file:d,task:h,...Ve({group:A})},...Ve(I)}}function W(d){return{id:cn(d.workload.id,"timing",d.configFingerprint),workloadId:d.workload.id,phase:"timing",instrumented:!1,configFingerprint:d.configFingerprint,trials:d.trials,timing:d.timing,warnings:d.warnings,artifacts:[],memory:d.heapUsed?{origin:"heapStats",heapUsedBeforeBytes:d.heapUsed.beforeBytes,heapUsedAfterBytes:d.heapUsed.afterBytes}:ct(d.trials),...Ve({interleaved:d.interleaved})}}function ct(d){let h=d.map((y)=>y.maxRssBytes).filter((y)=>y!==void 0);if(h.length===0)return;return{origin:"resourceUsage",maxRssBytes:Math.max(...h)}}function P(d){return{id:cn(d.workload.id,d.phase,d.configFingerprint),workloadId:d.workload.id,phase:d.phase,instrumented:!0,configFingerprint:d.configFingerprint,trials:[{i:0,wallNs:d.diagnosticWallNs,exitCode:d.exitCode}],diagnosticWallNs:d.diagnosticWallNs,cpu:d.cpu,heap:d.heap,memory:d.memory,jit:d.jit,warnings:d.warnings,artifacts:d.artifacts}}function Xe(d){return{id:cn(d.workload.id,"paired",d.configFingerprint),workloadId:d.workload.id,phase:"paired",instrumented:!1,configFingerprint:d.configFingerprint,trials:[],..."threw"in d?{threw:d.threw}:{timing:d.timing,paired:d.paired},diagnosticWallNs:d.diagnosticWallNs,warnings:d.warnings,artifacts:[]}}async function fn(d,h,y){let x=await Bun.file(y).arrayBuffer();return{id:n("art",d,h,y),kind:h,path:y,sha256:Bun.CryptoHasher.hash("sha256",x,"hex"),bytes:x.byteLength}}function i(d){return n("cfg",d)}function Y(d){return`${S(d,2)}
10
- `}async function Qe(d,h){let y=`${h}.tmp-${process.pid}-${crypto.randomUUID().slice(0,8)}`;try{await Bun.write(y,d),await it(y,h)}catch(x){throw await st(y,{force:!0}),x}}async function u(d,h){await Qe(Y(d),h)}class E extends Error{code;path;schemaVersion;constructor(d,h,y={}){super(h);this.name="OstiaDocumentError",this.code=d,this.path=y.path,this.schemaVersion=y.schemaVersion}}async function a(d){let h=await Bun.file(d).text(),y;try{y=JSON.parse(h)}catch(M){let A=T(M);throw new E("invalid-json",`${d}: invalid JSON (${A})`,{path:d})}let x=y!==null&&typeof y==="object"?y.schemaVersion:void 0;if(typeof x!=="number")throw new E("not-a-document",`${d}: not a ProfileDocument (missing schemaVersion)`,{path:d});if(x!==2)throw new E("unsupported-schema",`${d}: unsupported ProfileDocument schemaVersion ${x} (this ostia reads 2)`,{path:d,schemaVersion:x});return mt(y,d),lt(pt(y))}var In=(d)=>typeof d==="object"&&d!==null&&!Array.isArray(d);function mt(d,h){let y=(x)=>new E("not-a-document",`${h}: malformed document: ${x}`,{path:h});if(!Array.isArray(d.workloads))throw y('"workloads" must be an array');if(!Array.isArray(d.measurements))throw y('"measurements" must be an array');d.workloads.forEach((x,M)=>{if(!In(x)||typeof x.id!=="string")throw y(`workloads[${M}] must be an object with a string "id"`)}),d.measurements.forEach((x,M)=>{if(!In(x)||typeof x.id!=="string"||typeof x.workloadId!=="string"||typeof x.phase!=="string")throw y(`measurements[${M}] must be an object with string "id", "workloadId" and "phase"`);for(let A of["trials","warnings","artifacts"])if(!Array.isArray(x[A]))throw y(`measurements[${M}].${A} must be an array`)})}function lt(d){let h=(y)=>{if(y.ratioP25!==void 0||y.p25===void 0)return;y.ratioP25=y.p25,y.ratioP75=y.p75,delete y.p25,delete y.p75};for(let y of d.measurements){if(!y.paired)continue;h(y.paired);for(let x of y.paired.repeats??[])h(x)}return d}function pt(d){for(let h of d.measurements){let y=h.timing;if(!y||y.mad!==void 0||y.samples.length===0)continue;h.timing={...c(y.samples),...y.batch!==void 0&&{batch:y.batch}}}return d}import bn from"os";var dt=200,$n=64,ft=(()=>{let d=new Uint8Array(4096);for(let h=0;h<d.length;h++)d[h]=h*2654435761&255;return d})();function gt(d,h){let y=h;for(let x=0;x<d.length;x++)y^=d[x],y=Math.imul(y,16777619);return y>>>0}function bt(d){let h=c(d);return{floorPct:h.median===0?0:h.mad/h.median*100,referenceMedianNs:h.median,samples:d.length}}function dn(d=dt){let h=d*1e6,y=[],x=0,M=Bun.nanoseconds();while(Bun.nanoseconds()-M<h){let A=Bun.nanoseconds();for(let I=0;I<$n;I++)x^=gt(ft,I);y.push((Bun.nanoseconds()-A)/$n)}return bt(y)}var Bn=0.75;function Pe(){let[d=0,h=0]=bn.loadavg();return{cpuModel:bn.cpus()[0]?.model??"unknown",cores:bn.availableParallelism(),loadAvg1:d,loadAvg5:h,noise:dn()}}function v(d){if(!d)return;let h=d.noise.referenceMedianNs,y=dn().referenceMedianNs;d.noise.driftPct=h>0?(y/h-1)*100:0}function xe(d){if(d.loadAvg1<=d.cores*Bn)return;return{code:"noisy-machine",message:`Load average ${d.loadAvg1.toFixed(2)} exceeds ${Bn*100}% of ${d.cores} available core(s); timing noise may be elevated.`,data:{loadAvg1:d.loadAvg1,cores:d.cores}}}function Z(d,h,y){return`${e(d,y)}\u2026${e(h,y)}`}function Me(d){return(d/1e6).toFixed(3)}function p(d){return(d/1000).toFixed(2)}function b(d){if(d<1024)return`${d.toFixed(0)}B`;if(d<1048576)return`${(d/1024).toFixed(2)}KiB`;return`${(d/1048576).toFixed(2)}MiB`}function N(d){return d?.name||"(anonymous)"}function Te(d,h){let y=d.totals.reduce((x,M)=>x+M.selfUs,0)||1;return d.totals.slice(0,h).map((x)=>({frame:d.frames[x.frameIx],selfUs:x.selfUs,totalUs:x.totalUs,pct:(x.selfUs/y*100).toFixed(1)}))}function Re(d){return`${d.objectCount??"?"} objects, ${b(d.heapSizeBytes??0)}`}function Se(d){return`${d.cpuModel} \xB7 ${d.cores} cores \xB7 load ${d.loadAvg1.toFixed(1)} \xB7 noise floor ${d.noise.floorPct.toFixed(1)}%`}function L(d){return`${d.sha} (${d.branch}${d.dirty?", dirty":""})`}function m(d){return d.label??d.command?.join(" ")??d.entry?.task??d.id}function s(d,h){return d?m(d):h}function ve(d,h){if(d===1)return h?"1.00\xD7 (baseline)":"1.00\xD7";if(d>1)return`${d.toFixed(2)}\xD7 slower`;return`${(1/d).toFixed(2)}\xD7 faster`}function gn(d){return d.replace(/\|/g,"\\|").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/`/g,"\\`").replace(/\r\n|\r|\n/g,"<br>")}function X(d){let h=[],y=[];for(let x of d.trials){if(x.timedOut||x.timeSourceNoMatch)continue;if(x.userNs===void 0||x.systemNs===void 0)continue;h.push(x.userNs),y.push(x.systemNs)}if(h.length===0)return;return{userNs:o(k(h),0.5),systemNs:o(k(y),0.5)}}function Ce(d){return`${e(d.userNs)}/${e(d.systemNs)}`}function t(d){let h=d.toFixed(1);if(Number(h)===0)return"0.0%";return`${d>0?"+":""}${h}%`}function C(d,h){return yt(h)?h:`${d}/${h}`}class On extends l{}function $e(d,h){if(!ht(h,{throwIfNoEntry:!1})?.isFile())throw new On(`Suite not found: ${d}`)}function Oe(d,h){return`${d}/${h}-tmp-${process.pid}-${crypto.randomUUID().slice(0,8)}`}function f(d){return o(Float64Array.from(d).sort(),0.5)}function w(d){return kt(d,{recursive:!0,force:!0})}async function en(d){return await Bun.file(d).exists()?a(d):void 0}var ce=3,wt=16777216;function Ae(d){let h=f(d.map((x)=>x.peakBytes)),y=Math.max(...d.map((x)=>x.slackBytes));if(y<wt||y<=h/4)return;return{code:"peak-hidden",message:`Before the call, earlier work in the process had freed up to ${b(y)} the allocator still held (module-scope setup or before hooks that allocate), which the call could reuse without RSS rising: this reading can be low by up to that much. Skip that work when process.env.OSTIA_PEAK_MEM is set.`,data:{slackBytes:y,processes:d.length}}}function O(d){let h=d===!1?void 0:Pe();return{environment:h,noiseWarning:h&&xe(h)}}function Ie(d,h,y){let x=d[0],M=d[d.length-1];if(!x||!M)return;if(h)x.warnings.push(h);if(y)M.warnings.push({code:"aborted",message:y})}async function Ee(d,h){let y=qe(h.timeoutMs,h.signal),x=Bun.spawn(d,{cwd:h.cwd,...h.env&&{env:{...process.env,...h.env}},stdout:"inherit",stderr:"inherit",stdin:"ignore",...h.ipc&&{ipc:h.ipc},...y.spawn});h.inFlight?.add(x);let M;try{M=await x.exited}finally{h.inFlight?.delete(x)}if(h.signal?.aborted)return!1;if(y.timedOut())throw Error(`${h.label} timed out after ${h.timeoutMs}ms: ${h.name}`);if(M!==0){let A=h.errorFile&&Bun.file(h.errorFile);throw Error(A&&await A.exists()?`${h.label} failed: ${h.name}: ${await A.text()}`:`${h.label} failed: ${h.name} (runner exited ${M})`)}return!0}function j(d){return d!==null&&typeof d==="object"&&typeof d.then==="function"}var xt=(async()=>{}).constructor,Tt=0,Un=256;function Ne(d,h){let y=`/* ostia task loop ${Tt++} */
11
- const t0 = Bun.nanoseconds()
12
- for (let b = 0; b < n; b++) sink[b & ${Un-1}] = ${h?"await ":""}fn()
13
- return Bun.nanoseconds() - t0`,x=(h?xt:Function)("fn","sink","n",y),M=Array(Un);return(A)=>x(d,M,A)}async function De(d){let h=Bun.nanoseconds(),y=d(),x=j(y),M=x?await y:y;return{isAsync:x,result:M,ns:Math.max(1,Bun.nanoseconds()-h)}}var wn=[],ge,Je;function kn(d,h,y,x){let M=ge,A=M?`${M.path}/${d}`:d;ge={path:A,chain:[...M?.chain??[],{path:A,before:y?.before,after:y?.after}],description:y?.description??M?.description,isolate:y?.isolate??M?.isolate,gc:y?.gc??M?.gc,cpu:y?.cpu??M?.cpu,alloc:y?.alloc??M?.alloc,peakMem:y?.peakMem??M?.peakMem,skip:x.skip||M?.skip,only:x.only||M?.only};try{h()}finally{ge=M}}var xn=Object.assign((d,h,y)=>kn(d,h,y,{}),{skip:(d,h,y)=>kn(d,h,y,{skip:!0}),only:(d,h,y)=>kn(d,h,y,{only:!0})});function yn(d,h,y,x){let M=Je!==void 0||y?.params!==void 0?{...Je,...y?.params}:void 0;wn.push({groupName:ge?.path,groupChain:ge?.chain,groupDescription:ge?.description,groupIsolate:ge?.isolate,groupGc:ge?.gc,groupCpu:ge?.cpu,groupAlloc:ge?.alloc,groupPeakMem:ge?.peakMem,name:d,fn:h,baseline:y?.baseline,params:M,skipped:x.skip||ge?.skip,only:x.only||ge?.only,opts:y})}var Mn=Object.assign((d,h,y)=>yn(d,h,y,{}),{skip:(d,h,y)=>yn(d,h,y,{skip:!0}),only:(d,h,y)=>yn(d,h,y,{only:!0})});function D(){return wn}function ue(){wn.length=0,ge=void 0,Je=void 0}function hn(d,h){let y=Je;Je=d;try{return h()}finally{Je=y}}function F(d){return d.groupName?`${d.groupName}/${d.name}`:d.name}function _e(d){return(d.opts?.aliases??[]).map((h)=>d.groupName?`${d.groupName}/${h}`:h)}function nn(d,h){return d.opts?.isolate??d.groupIsolate??h}function Cn(d,h){return d.opts?.gc??d.groupGc??h}function _n(d,h){return d.opts?.cpu??d.groupCpu??h}function We(d,h){return d.opts?.alloc??d.groupAlloc??h}function de(d,h){return d.opts?.peakMem??d.groupPeakMem??h}function Le(d){let h=new Map,y=new Map;return d.forEach((x,M)=>{if(x.skipped)return;for(let{path:A}of x.groupChain??[]){if(!h.has(A))h.set(A,M);y.set(A,M)}}),(x)=>{let M=(d[x].groupChain??[]).map((A)=>A.path);return{enter:M.filter((A)=>h.get(A)===x),leave:M.filter((A)=>y.get(A)===x).reverse()}}}async function g(d,h,y){let x=d.groupChain??[],M=y??(h==="before"?x:[...x].reverse()).map((A)=>A.path);for(let A of M)await x.find((I)=>I.path===A)?.[h]?.()}function tn(d,h){if(!h)return[...d];let y=new RegExp(h);return d.filter((x)=>y.test(F(x)))}function B(d,h,y,x=!0){let M=d.filter((G)=>G.only),A=M.length>0?M:d;if(x&&M.length>0)process.stderr.write(`bench: ${M.length} task(s) selected by .only
14
- `);let I=tn(A,h);if(I.length===0)throw Error(`filter ${JSON.stringify(h)} matched zero of ${A.length} registered task(s) in ${y}.`);return I}function Q(d){return d.samples?.nodeIds.length??d.totals.reduce((h,y)=>h+y.samples,0)}import{heapSize as zn}from"bun:jsc";import{heapStats as Dn}from"bun:jsc";var St=100,Mt=1000;async function le(d,h=St,y=Mt){let x=Bun.nanoseconds();Bun.gc(!0);let M=Dn().heapSize,A=Bun.nanoseconds()+y*1e6,I=0;while(I<h&&(I===0||Bun.nanoseconds()<A)){let J=d();if(j(J))await J;I++}Bun.gc(!0);let G=Dn().heapSize,_=Bun.nanoseconds()-x;return{memory:{origin:"heapStats",kind:"retained",bytesPerOp:Math.max(0,(G-M)/I)},calls:I,diagnosticWallNs:_}}import{profile as vt}from"bun:jsc";var je=1000;function Fe(){let d=new Map,h=[];return{frames:h,intern(y,x,M,A){let I=d.get(y);if(I===void 0)I=new Map,d.set(y,I);let G=x??"",_=I.get(G);if(_===void 0)_=h.length,I.set(G,_),h.push({key:n("fr",y,G),name:y,url:x,line:M,col:A});return _}}}function Be(d,h,y,x,M){let A=d.get(h);if(A)A.selfUs+=y,A.totalUs+=x,A.samples+=M;else d.set(h,{frameIx:h,selfUs:y,totalUs:x,samples:M})}function Ue(d){return[...d.values()].sort((h,y)=>y.selfUs-h.selfUs)}var Rt=new Map([["LLInt","llint"],["Baseline","baseline"],["DFG","dfg"],["FTL","ftl"]]),Wn=4294967295;function Ln(d,h){let y=h??d.interval*1e6,{frames:x,intern:M}=Fe();function A(K){let z=K.line===Wn,V=z?void 0:K.line-1,ie=z||K.column===Wn?void 0:K.column-1;return M(K.name,K.sourceURL,V,ie)}let I=[];function G(K){let z={id:I.length,frameIx:K,children:new Map,selfUs:0,samples:0,totalUs:0};return I.push(z),z}let _=G(M("(root)",void 0,void 0,void 0)),J={llint:0,baseline:0,dfg:0,ftl:0},H=new Map,ne=[],oe=[];for(let K of d.traces){let z=K.frames,V=_;for(let Ge=z.length-1;Ge>=0;Ge--){let Ze=A(z[Ge]),ze=V.children.get(Ze);if(!ze)ze=G(Ze),V.children.set(Ze,ze);V=ze}V.selfUs+=y,V.samples+=1,ne.push(V.id),oe.push(y);let ie=z[0],Ke=ie&&Rt.get(ie.category);if(Ke){J[Ke]++;let Ge=H.get(Ke)??new Map;Ge.set(V.frameIx,(Ge.get(V.frameIx)??0)+1),H.set(Ke,Ge)}}function be(K){let z=K.selfUs;for(let V of K.children.values())z+=be(V);return K.totalUs=z,z}be(_);let ee=new Map;function re(K){Be(ee,K.frameIx,K.selfUs,K.totalUs,K.samples);for(let z of K.children.values())re(z)}re(_);let te=I.map((K)=>({id:K.id,frameIx:K.frameIx,children:[...K.children.values()].map((z)=>z.id)})),se={origin:"jsc-profile",samplingIntervalUs:y,frames:x,nodes:te,totals:Ue(ee),samples:{nodeIds:ne,timeDeltasUs:oe}},fe=[...H.entries()].flatMap(([K,z])=>[...z.entries()].sort((V,ie)=>ie[1]-V[1]).slice(0,3).map(([V,ie])=>({tier:K,frameKey:x[V].key,samples:ie})));return{cpu:se,jit:{origin:"jsc-profile",tiers:J,topFramesByTier:fe}}}async function He(d,h={}){let y=h.intervalUs??je,x,M=Bun.nanoseconds(),A=await vt(async()=>(x=await d(),x),y),I=Bun.nanoseconds()-M,{cpu:G,jit:_}=Ln(A.stackTraces,y);return{result:x,cpu:G,jit:_,diagnosticWallNs:I}}var Sn=100,Ye=2000,Pt=2,Et=200,Nt=1e4,Ft=Ye/2,At=20;function It(d){let h=Ye*Pt*d/1000;return Math.min(Nt,Math.max(Et,h))}async function Gn(d,h={}){let y=h.intervalUs??Sn,x=It(y)*1e6,M=async()=>{let J=Bun.nanoseconds();do{let H=d();if(j(H))await H}while(Bun.nanoseconds()-J<x)},{cpu:A,jit:I,diagnosticWallNs:G}=await He(M,{intervalUs:y}),_=[$t(A),Bt(I)].filter((J)=>J!==void 0);return{cpu:A,jit:I,diagnosticWallNs:G,warnings:_}}function $t(d){let h=Q(d);if(h>=Ft)return;return{code:"low-sample-count",message:`Only ${h} CPU sample(s) at ${d.samplingIntervalUs}\xB5s (target ${Ye}); frame shares this thin move several points between runs. Lower --cpu-interval for more.`,data:{samples:h,target:Ye,intervalUs:d.samplingIntervalUs}}}function Bt(d){let{llint:h,baseline:y,dfg:x,ftl:M}=d.tiers,A=h+y+x+M;if(A===0)return;let I=h/A*100,G=y/A*100,_=x/A*100,J=M/A*100;if(I+G<=At)return;return{code:"jit-cold",message:`${(I+G).toFixed(1)}% of CPU samples were in the llint/baseline tiers: the JIT never warmed this task up.`,data:{llintPct:I,baselinePct:G,dfgPct:_,ftlPct:J}}}var Ot=500,Ut=20,jn=3,Ct=10,_t=2,Dt=0.1,Wt=1000,Jn=1e4,Lt=2*Jn,Gt=1e6,jt=5;function Vn(d){let h=Math.log10(Math.max(1,d)/1e6),y=Math.round(jn+_t*h);return Math.min(Ct,Math.max(jn,y))}function Ht(d,h){let y=Math.floor(h/d);return Math.min(Ut,Math.max(y,Vn(d)))}var Jt;function Tn(d){Jt=d}function Hn(d,h){return Math.max(1,Math.ceil(Wt/d),Math.ceil(h/(d*Jn)))}function Vt(d){let h=[...d].sort((y,x)=>y-x);return h[h.length>>1]}async function Kn(d,h={}){let y=(h.budgetMs??Ot)*1e6,x=y*(h.warmup??Dt),M=await De(d),A=M.ns,I=Ne(d,M.isAsync),G=Bun.nanoseconds(),_=1;while(Bun.nanoseconds()-G<x){let z=await I(_);if(A=Math.max(1,z/_),z<Gt)_*=2}let J=Hn(A,y);if(J>1){let z=[];for(let V=0;V<jt;V++)z.push(await I(J)/J);A=Math.max(1,Vt(z)),J=Hn(A,y)}let H=A*J,ne=h.samples??h.minSamples??Ht(H,y),oe=h.samples!==void 0?0:y,be=h.samples??Math.max(Lt,ne),ee=[],re=Bun.nanoseconds(),te=0,se=0;while(se<ne||te<oe&&se<be){let z=await I(J);if(ee.push({i:se,wallNs:z/J}),se++,te=Bun.nanoseconds()-re,h.gc)Bun.gc(!0)}let fe=c(ee.map((z)=>z.wallNs));if(J>1)fe.batch=J;let he=ke(fe,[],"inprocess"),K=Vn(H);if(ee.length<K)he.push({code:"low-sample-count",message:`Only ${ee.length} sample(s) at ~${e(H)} per trial; ${K} is the floor for this cost class. Raise minSamples or the time budget for a steadier number.`,data:{samples:ee.length,target:K,trialCostNs:H}});return{trials:ee,timing:fe,warnings:he}}function U(d,h,y){let x=F(h),M=_e(h).map((A)=>mn(d,A,{params:h.params}).id);return mn(d,x,{label:x,formerIds:M.length>0?M:void 0,baseline:h.baseline,group:h.groupName,description:h.opts?.description,groupDescription:h.groupDescription,isolated:y,params:h.params,skipped:h.skipped})}async function pe(d,h,y){let x=h.some((J)=>!J.skipped),{environment:M,noiseWarning:A}=O(x?y.noiseCheck:!1),I=Le(h),G=[],_=[];for(let J=0;J<h.length;J++){let H=h[J],ne=U(d,H,y.markIsolated);if(G.push(ne),H.skipped)continue;let{enter:oe,leave:be}=I(J);if(await g(H,"before",oe),H.opts?.before)await H.opts.before();let ee={budgetMs:H.opts?.budgetMs??y.budgetMs,samples:H.opts?.samples??y.samples,minSamples:H.opts?.minSamples??y.minSamples,warmup:y.warmup,gc:Cn(H,y.gc??!1)},re=zn(),te=await Kn(H.fn,ee),se=zn();if(_.push(W({workload:ne,heapUsed:{beforeBytes:re,afterBytes:se},configFingerprint:i({budgetMs:ee.budgetMs??null,samples:ee.samples??null,minSamples:ee.minSamples??null,gc:ee.gc??!1}),trials:te.trials,timing:te.timing,warnings:A&&_.length===0?[...te.warnings,A]:te.warnings})),_n(H,y.cpu??!1)){let fe=y.cpuIntervalUs??Sn,he=await Gn(H.fn,{intervalUs:fe});_.push(P({workload:ne,phase:"cpu",configFingerprint:i({cpu:!0,intervalUs:fe}),diagnosticWallNs:he.diagnosticWallNs,cpu:he.cpu,jit:he.jit,warnings:he.warnings,artifacts:[]}))}if(We(H,y.alloc??!1)){let fe=await le(H.fn);_.push(P({workload:ne,phase:"memstats",configFingerprint:i({alloc:!0}),diagnosticWallNs:fe.diagnosticWallNs,memory:fe.memory,warnings:[],artifacts:[]}))}if(H.opts?.after)await H.opts.after();await g(H,"after",be)}return v(M),r(G,_,M)}
15
- export{T,l,we,ln,ye,q,R,e,c,k,o,ke,ae,S,n,r,me,pn,W,P,Xe,fn,i,Y,Qe,u,E,a,Pe,v,xe,Z,Me,p,b,N,Te,Re,Se,L,m,s,ve,gn,X,Ce,t,C,$e,Oe,f,w,en,ce,Ae,O,Ie,Ee,j,Ne,De,Fe,Be,Ue,xn,Mn,D,ue,hn,F,_e,nn,We,de,Le,g,tn,B,Q,le,je,He,Tn,U,pe};
package/chunk-82vs1rw1.js DELETED
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{rn,Ge,Ve,Je,ze,on,ee,sn}from"./chunk-scvezzm9.js";export{Ve as AB_HELP,ee as BASELINE_HELP,Ge as BENCH_HELP,on as CI_HELP,Je as COMPARE_HELP,sn as MAIN_HELP,ze as REPORT_HELP,rn as TIME_HELP};
package/chunk-dvqggjkn.js DELETED
@@ -1,14 +0,0 @@
1
- // @bun
2
- import{j}from"./chunk-5m601yfv.js";import{heapStats as w}from"bun:jsc";function H(){let{heapSize:o,extraMemorySize:e}=w(),s=process.memoryUsage.rss();return{rssBytes:s,residentBytes:f()??s,liveBytes:o+e}}function f(){if(process.platform!=="darwin")return;let o=Bun.spawnSync(["ps","-o","rss=","-p",String(process.pid)],{stderr:"ignore"}),e=Number(o.stdout.toString().trim());return o.success&&e>0?e*1024:void 0}var t={ready:1,go:2,sampling:3,stop:4},g=`self.onmessage = (event) => {
3
- const slots = new Int32Array(event.data)
4
- Atomics.store(slots, 0, ${t.ready})
5
- Atomics.wait(slots, 0, ${t.ready})
6
- if (Atomics.compareExchange(slots, 0, ${t.go}, ${t.sampling}) === ${t.go}) {
7
- while (Atomics.load(slots, 0) === ${t.sampling}) {
8
- const kib = (process.memoryUsage.rss() / 1024) | 0
9
- if (kib > Atomics.load(slots, 1)) Atomics.store(slots, 1, kib)
10
- }
11
- }
12
- postMessage(0)
13
- }`,d=1e4;async function G(o=g){let e=new Int32Array(new SharedArrayBuffer(8)),s=new Worker(URL.createObjectURL(new Blob([o],{type:"application/javascript"}))),a=new Promise((r,c)=>{let n=(m)=>c(Error(`RSS sampler worker failed: ${m}`));s.onerror=(m)=>n(m.message||"uncaught error"),s.addEventListener("close",()=>n("worker exited unexpectedly"))});a.catch(()=>{});let i=new Promise((r)=>{s.onmessage=r});try{s.postMessage(e.buffer);let r=Date.now()+d;while(Atomics.load(e,0)!==t.ready){if(Date.now()>r)throw Error("RSS sampler worker failed: did not start in time");await Promise.race([Bun.sleep(1),a])}}catch(r){throw s.terminate(),r}return{async during(r){try{Atomics.store(e,0,t.go),Atomics.notify(e,0);let c=Bun.nanoseconds()+50000000;while(Atomics.load(e,0)!==t.sampling&&Bun.nanoseconds()<c);let n=Date.now()+d;while(Atomics.load(e,0)!==t.sampling){if(Date.now()>n)throw Error("RSS sampler worker failed: did not start sampling");await Promise.race([Bun.sleep(1),a])}return await r(),Atomics.store(e,0,t.stop),await Promise.race([i,a]),Atomics.load(e,1)*1024}finally{s.terminate()}}}}async function ne(o,e,s){let a=s??await G();Bun.gc(!0);let i=H(),r=process.resourceUsage().maxRSS*1024,c=Bun.nanoseconds(),n=0,m=await a.during(async()=>{let p=o();if(j(p))await p;n=Bun.nanoseconds()-c}),l=process.resourceUsage().maxRSS*1024,u=Math.max(m,l>r?l:0),y=e?i.residentBytes-e.residentBytes-(i.liveBytes-e.liveBytes):0;return{peakBytes:Math.max(0,u-i.rssBytes),slackBytes:Math.max(0,y),wallNs:n}}
14
- export{H,G,ne};
package/chunk-fc36fd0b.js DELETED
@@ -1,3 +0,0 @@
1
- // @bun
2
- import{k,o,Ne,De}from"./chunk-5m601yfv.js";function y(n){return n==="cand"?"candidate":n}class se extends Error{side;constructor(n,t){super(t instanceof Error?t.message:String(t),{cause:t});this.side=n}}async function R(n,t){try{return await t()}catch(r){throw r instanceof se?r:new se(n,r)}}var C=15,_=1e7,N=1e6,O=3;async function un(n,t,r={}){let i=r.rounds??C,{signal:s}=r;s?.throwIfAborted();let m=Bun.nanoseconds(),c=r.candFirst?["cand","base"]:["base","cand"],b=c.toReversed(),h={base:n,cand:t},p={};for(let e of c)p[e]=await R(e,()=>De(h[e]));let M=Bun.deepEquals(p.base.result,p.cand.result),g=(e)=>{let a=Ne(h[e],p[e].isAsync);return(d)=>R(e,()=>a(d))},f={base:g("base"),cand:g("cand")},A=async(e)=>{for(let a=1;;a*=2){s?.throwIfAborted();let d=await e(a);if(d>=N)return Math.max(1,d/a)}},l={base:0,cand:0};for(let e of c)l[e]=await A(f[e]);let u=Math.max(1,Math.round(_/Math.max(l.base,l.cand)));for(let e=0;e<O;e++){s?.throwIfAborted();for(let a of c)await f[a](u)}let S=[],x=[],w=[];for(let e=0;e<i;e++){s?.throwIfAborted();let a={base:0,cand:0};for(let P of e%2===0?c:b)a[P]=await f[P](u);let d=Math.max(1,a.base),T=Math.max(1,a.cand);S.push(d/u),x.push(T/u),w.push(T/d)}return{rounds:i,batch:u,baseSamples:S,candSamples:x,ratios:w,sameOutput:M,diagnosticWallNs:Bun.nanoseconds()-m}}function I(n){return!(n.suiteChanged&&!n.sameOutput)}function dn(n,t,r,i){let s=t-n,m=Math.abs(s)>Math.max(i,n*r/100);return{baseBytes:n,candBytes:t,verdict:!m?"unchanged":s>0?"regressed":"improved",floorBytes:i}}function ie(n,t){let r=k(n),i=o(r,0.5),s=o(r,0.25),m=o(r,0.75),c=t/100,b=i>1+c&&s>1?"regressed":i<1-c&&m<1?"improved":void 0;return{medianRatio:i,ratioP25:s,ratioP75:m,...b&&{flagged:b}}}
3
- export{y,se,un,I,dn,ie};