ostia 0.3.1 → 0.4.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/index.d.ts CHANGED
@@ -106,7 +106,7 @@ export type AbProgress = {
106
106
  side: Side;
107
107
  label: string;
108
108
  };
109
- type Side = "base" | "cand";
109
+ export type Side = "base" | "cand";
110
110
  /** Paired A/B timing of suite files against a git ref: every task runs on
111
111
  * the ref's committed tree (base) and the working tree (candidate) in one
112
112
  * process, alternating short batches, and is judged on the per-round time
@@ -212,7 +212,7 @@ export interface Workload {
212
212
  * `unchanged` with a `skipped` warning. */
213
213
  skipped?: boolean;
214
214
  }
215
- interface Measurement {
215
+ export interface Measurement {
216
216
  id: string;
217
217
  workloadId: string;
218
218
  phase: Phase;
@@ -385,7 +385,7 @@ interface InstructionStats {
385
385
  /**
386
386
  * Evidence of a `phase: "paired"` measurement: base and candidate
387
387
  * alternate in batches in one process, so drift cancels in the ratio. */
388
- interface PairedEvidence {
388
+ export interface PairedEvidence {
389
389
  /** One base batch and one candidate batch per round, alternating order. */
390
390
  rounds: number;
391
391
  /** Calls per side per round. */
@@ -485,7 +485,7 @@ export type WarningCode = (typeof WARNING_CODES)[number];
485
485
  * Every `Warning.code`. A runtime array so a test can assert each is
486
486
  * emitted.
487
487
  */
488
- declare const WARNING_CODES: readonly [
488
+ export declare const WARNING_CODES: readonly [
489
489
  "slow-first-run",
490
490
  "outliers-detected",
491
491
  "fast-command",
@@ -564,7 +564,7 @@ export interface Comparison {
564
564
  verdict: "pass" | "fail";
565
565
  }
566
566
  /** Aggregate view over a `compareDocuments` call's `Comparison[]`. */
567
- interface ComparisonSummary {
567
+ export interface ComparisonSummary {
568
568
  /** `comparisons.length`. */
569
569
  matched: number;
570
570
  regressed: number;
@@ -591,7 +591,7 @@ interface ComparisonSummary {
591
591
  * One task of a `compare`/`ci` run: matched on both sides, or present on
592
592
  * only one (`missing-base`: new, or renamed without an alias;
593
593
  * `missing-cand`: removed, or renamed). Times in ns, memory in bytes. */
594
- interface ComparedTask {
594
+ export interface ComparedTask {
595
595
  /** The candidate's workload id; the base's on a `missing-cand` task. */
596
596
  workloadId: string;
597
597
  /** Display name: the label, else the command, else the id. */
@@ -642,7 +642,7 @@ interface MemoryDelta {
642
642
  candBytes: number;
643
643
  deltaPct: number;
644
644
  }
645
- interface Environment {
645
+ export interface Environment {
646
646
  cpuModel: string;
647
647
  cores: number;
648
648
  loadAvg1: number;
@@ -663,7 +663,7 @@ interface NoiseFloor {
663
663
  driftPct?: number;
664
664
  }
665
665
  /** Run-level result of `ab()`, stamped on the document as `ab`. */
666
- interface AbSummary {
666
+ export interface AbSummary {
667
667
  base: {
668
668
  ref: string;
669
669
  sha: string;
@@ -719,7 +719,7 @@ interface AbSummary {
719
719
  * any task's memory regressed. */
720
720
  verdict: "pass" | "fail";
721
721
  }
722
- interface GitMetadata {
722
+ export interface GitMetadata {
723
723
  sha: string;
724
724
  branch: string;
725
725
  dirty: boolean;
@@ -730,7 +730,7 @@ export declare class AbBaseError extends OstiaUsageError {
730
730
  /** The caller's input can't be run as given (missing suite, bad ref, absent
731
731
  * baseline): the CLI reports it as a usage error (exit 2) rather than an
732
732
  * internal failure. */
733
- declare class OstiaUsageError extends Error {
733
+ export declare class OstiaUsageError extends Error {
734
734
  }
735
735
  /** A `baseSetup` command exited non-zero or timed out. The message names
736
736
  * the command and ends with the tail of its output. */
@@ -869,7 +869,7 @@ export interface GroupOptions {
869
869
  after?: Hook;
870
870
  }
871
871
  /** A task body or hook; it may return a promise, which the runner awaits. */
872
- type Hook = () => unknown;
872
+ export type Hook = () => unknown;
873
873
  export interface TaskOptions {
874
874
  /**
875
875
  * Marks this task as the Relative reference for its group in the table
@@ -941,9 +941,7 @@ export interface TaskOptions {
941
941
  * process/no-per-trial caveats as `before`. */
942
942
  after?: Hook;
943
943
  }
944
- /** Registers the tasks `fn` declares under the group `name`. */
945
- export declare const group: GroupFn;
946
- interface GroupFn extends GroupRegistrar {
944
+ export interface GroupFn extends GroupRegistrar {
947
945
  /**
948
946
  * Registers every task inside as skipped: the runner never measures
949
947
  * them, but the document still carries their workloads (marked
@@ -956,9 +954,7 @@ interface GroupFn extends GroupRegistrar {
956
954
  only: GroupRegistrar;
957
955
  }
958
956
  type GroupRegistrar = (name: string, fn: () => void, opts?: GroupOptions) => void;
959
- /** Registers `fn` as a benchmark task named `name` in the current group. */
960
- export declare const task: TaskFn;
961
- interface TaskFn extends TaskRegistrar {
957
+ export interface TaskFn extends TaskRegistrar {
962
958
  /**
963
959
  * Registers the task as skipped: the runner never measures it, but the
964
960
  * document still carries its workload (marked `Workload.skipped`) so a
@@ -972,15 +968,11 @@ interface TaskFn extends TaskRegistrar {
972
968
  only: TaskRegistrar;
973
969
  }
974
970
  type TaskRegistrar = (name: string, fn: Hook, opts?: TaskOptions) => void;
975
- export interface RunOptions extends MeasureTasksOpts {
976
- /** Regex matched against "group/name" task ids, as in `bench({ filter })`. */
977
- filter?: string;
978
- /** Skip printing the report to stdout; still returns the document. */
979
- quiet?: boolean;
980
- /** Renderer used for the printed report (default: `"table"`). */
981
- format?: FormatName;
982
- }
983
- interface MeasureTasksOpts extends InprocessTimingOptions {
971
+ /** Registers the tasks `fn` declares under the group `name`. */
972
+ export declare const group: GroupFn;
973
+ /** Registers `fn` as a benchmark task named `name` in the current group. */
974
+ export declare const task: TaskFn;
975
+ export interface MeasureTasksOpts extends InprocessTimingOptions {
984
976
  /**
985
977
  * Suite-wide default for capturing an extra `phase: "cpu"` measurement per
986
978
  * task (task/group `cpu` still wins). */
@@ -1012,7 +1004,15 @@ interface InprocessTimingOptions {
1012
1004
  warmup?: number;
1013
1005
  gc?: boolean;
1014
1006
  }
1015
- type FormatName = "table" | "json" | "markdown" | "jsonl" | "minimal" | "collapsed" | "mermaid" | "speedscope" | "cpuprofile";
1007
+ export interface RunOptions extends MeasureTasksOpts {
1008
+ /** Regex matched against "group/name" task ids, as in `bench({ filter })`. */
1009
+ filter?: string;
1010
+ /** Skip printing the report to stdout; still returns the document. */
1011
+ quiet?: boolean;
1012
+ /** Renderer used for the printed report (default: `"table"`). */
1013
+ format?: FormatName;
1014
+ }
1015
+ export type FormatName = "table" | "json" | "markdown" | "jsonl" | "minimal" | "collapsed" | "mermaid" | "speedscope" | "cpuprofile";
1016
1016
  /** In-file entrypoint: call at the bottom of a suite file run directly with
1017
1017
  * `bun suite.ts` to measure every registered `group()`/`task()`, print a
1018
1018
  * report, and return the document.
@@ -1021,6 +1021,9 @@ type FormatName = "table" | "json" | "markdown" | "jsonl" | "minimal" | "collaps
1021
1021
  * ignored. Prefer `ostia bench`/`bench()` for numbers you'll
1022
1022
  * `compare`/`ci` against. */
1023
1023
  export declare function run(opts?: RunOptions): Promise<ProfileDocument>;
1024
+ export type SweepPoint<T extends Record<string, readonly unknown[]>> = {
1025
+ [K in keyof T]: T[K][number];
1026
+ };
1024
1027
  /** Cartesian product over `dims`, calling `fn` once per point. Inside `fn`,
1025
1028
  * `task()` calls automatically inherit the point as their params (an
1026
1029
  * explicit `TaskOptions.params` merges over it, explicit keys win):
@@ -1033,9 +1036,6 @@ export declare function run(opts?: RunOptions): Promise<ProfileDocument>;
1033
1036
  * })
1034
1037
  */
1035
1038
  export declare function sweep<T extends Record<string, readonly unknown[]>>(dims: T, fn: (point: SweepPoint<T>) => void): void;
1036
- type SweepPoint<T extends Record<string, readonly unknown[]>> = {
1037
- [K in keyof T]: T[K][number];
1038
- };
1039
1039
  export interface CompareResult {
1040
1040
  comparisons: Comparison[];
1041
1041
  unmatched: {
@@ -1100,6 +1100,41 @@ export interface AbConfig {
1100
1100
  * `--mem-threshold` overrides. Default: 10. */
1101
1101
  memThresholdPct?: number;
1102
1102
  }
1103
+ export interface BenchConfig {
1104
+ /**
1105
+ * Suite file globs, resolved against the config's directory (e.g.
1106
+ * "bench/**\/*.bench.ts"). Suite files given on the command line replace
1107
+ * this list. */
1108
+ suites?: string[];
1109
+ /**
1110
+ * Per-suite `preload`/`bunFlags`, so one tier (e.g. DOM-dependent suites)
1111
+ * can pay for a setup the others don't need. The first project whose
1112
+ * `suites` match a file wins; a file no project matches gets the top-level
1113
+ * `preload`/`bunFlags`. `--preload` / `--bun-flags` replace the matching
1114
+ * field for every file. */
1115
+ projects?: BenchProject[];
1116
+ preload?: string[];
1117
+ /**
1118
+ * Extra flags for the `bun` process that runs each suite file; see
1119
+ * `BenchOptions.bunFlags`. `--bun-flags` replaces this list. */
1120
+ bunFlags?: string[];
1121
+ jobs?: number | "auto";
1122
+ budgetMs?: number;
1123
+ samples?: number;
1124
+ minSamples?: number;
1125
+ gc?: boolean;
1126
+ cpu?: boolean;
1127
+ cpuIntervalUs?: number;
1128
+ alloc?: boolean;
1129
+ peakMem?: boolean;
1130
+ filter?: string;
1131
+ isolate?: boolean;
1132
+ outDir?: string;
1133
+ /**
1134
+ * Kills a suite file's (or isolated task's) subprocess after this many
1135
+ * ms; overrides `ostia ci`'s 10-minute default. */
1136
+ timeoutMs?: number;
1137
+ }
1103
1138
  export interface OstiaConfig {
1104
1139
  /** `command` workloads: exact trial count; see `time()`. */
1105
1140
  samples?: number;
@@ -1192,41 +1227,6 @@ export interface TimeSource {
1192
1227
  unit?: TimeUnit;
1193
1228
  }
1194
1229
  export type TimeUnit = "ns" | "us" | "ms" | "s";
1195
- interface BenchConfig {
1196
- /**
1197
- * Suite file globs, resolved against the config's directory (e.g.
1198
- * "bench/**\/*.bench.ts"). Suite files given on the command line replace
1199
- * this list. */
1200
- suites?: string[];
1201
- /**
1202
- * Per-suite `preload`/`bunFlags`, so one tier (e.g. DOM-dependent suites)
1203
- * can pay for a setup the others don't need. The first project whose
1204
- * `suites` match a file wins; a file no project matches gets the top-level
1205
- * `preload`/`bunFlags`. `--preload` / `--bun-flags` replace the matching
1206
- * field for every file. */
1207
- projects?: BenchProject[];
1208
- preload?: string[];
1209
- /**
1210
- * Extra flags for the `bun` process that runs each suite file; see
1211
- * `BenchOptions.bunFlags`. `--bun-flags` replaces this list. */
1212
- bunFlags?: string[];
1213
- jobs?: number | "auto";
1214
- budgetMs?: number;
1215
- samples?: number;
1216
- minSamples?: number;
1217
- gc?: boolean;
1218
- cpu?: boolean;
1219
- cpuIntervalUs?: number;
1220
- alloc?: boolean;
1221
- peakMem?: boolean;
1222
- filter?: string;
1223
- isolate?: boolean;
1224
- outDir?: string;
1225
- /**
1226
- * Kills a suite file's (or isolated task's) subprocess after this many
1227
- * ms; overrides `ostia ci`'s 10-minute default. */
1228
- timeoutMs?: number;
1229
- }
1230
1230
  export type OstiaConfigInput = Omit<Partial<OstiaConfig>, "thresholds"> & {
1231
1231
  thresholds?: Partial<Thresholds>;
1232
1232
  };
@@ -1306,7 +1306,7 @@ export declare const renderers: {
1306
1306
  speedscope: Renderer<VizOptions>;
1307
1307
  cpuprofile: Renderer<VizOptions>;
1308
1308
  };
1309
- interface Renderer<O = unknown> {
1309
+ export interface Renderer<O = unknown> {
1310
1310
  name: FormatName;
1311
1311
  render(doc: ProfileDocument, options: O): Promise<RenderResult>;
1312
1312
  }
@@ -1356,7 +1356,7 @@ export type MinimalEvent = MinimalRunLine | MinimalUnmatchedLine | MinimalSummar
1356
1356
  /**
1357
1357
  * One per timing run, for piping into an agent's context in place of the
1358
1358
  * full `ProfileDocument`. Numbers stay in the IR's units (ns). */
1359
- interface MinimalRunLine {
1359
+ export interface MinimalRunLine {
1360
1360
  event: "run";
1361
1361
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
1362
1362
  schemaVersion: ProfileDocument["schemaVersion"];
@@ -1495,7 +1495,7 @@ interface MinimalMemoryChange {
1495
1495
  floor: number;
1496
1496
  }
1497
1497
  /** A workload present on only one side of a `compare`/`ci` run. */
1498
- interface MinimalUnmatchedLine {
1498
+ export interface MinimalUnmatchedLine {
1499
1499
  event: "unmatched";
1500
1500
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
1501
1501
  workloadId: string;
@@ -1505,7 +1505,7 @@ interface MinimalUnmatchedLine {
1505
1505
  /**
1506
1506
  * The last line of a `compare`/`ci`/`ab` run; never emitted for a bare
1507
1507
  * `time`/`bench` document. */
1508
- interface MinimalSummaryLine {
1508
+ export interface MinimalSummaryLine {
1509
1509
  event: "summary";
1510
1510
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
1511
1511
  command: "compare" | "ci" | "ab";
@@ -1641,3 +1641,4 @@ export interface TimeOptions {
1641
1641
  export declare function time(opts: TimeOptions): Promise<ProfileDocument>;
1642
1642
  /** Identity function that types an `ostia.config.ts` default export. */
1643
1643
  export declare function defineConfig(config: OstiaConfigInput): OstiaConfigInput;
1644
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ostia",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Fast profiling and benchmarking for Bun.",
5
5
  "license": "MIT",
6
6
  "author": "Eric Liu (https://github.com/metonym)",
@@ -5,7 +5,7 @@ export const NO_TASKS_HINT =
5
5
  " If the suite does call task(), it imports a different copy of ostia than the CLI running it (a global install, or another version): run the one from the project's node_modules.";
6
6
 
7
7
  /** A task body or hook; it may return a promise, which the runner awaits. */
8
- type Hook = () => unknown;
8
+ export type Hook = () => unknown;
9
9
 
10
10
  export interface TaskOptions {
11
11
  /**
@@ -207,7 +207,7 @@ type GroupRegistrar = (
207
207
  opts?: GroupOptions,
208
208
  ) => void;
209
209
 
210
- interface GroupFn extends GroupRegistrar {
210
+ export interface GroupFn extends GroupRegistrar {
211
211
  /**
212
212
  * Registers every task inside as skipped: the runner never measures
213
213
  * them, but the document still carries their workloads (marked
@@ -263,7 +263,7 @@ function registerTask(
263
263
 
264
264
  type TaskRegistrar = (name: string, fn: Hook, opts?: TaskOptions) => void;
265
265
 
266
- interface TaskFn extends TaskRegistrar {
266
+ export interface TaskFn extends TaskRegistrar {
267
267
  /**
268
268
  * Registers the task as skipped: the runner never measures it, but the
269
269
  * document still carries its workload (marked `Workload.skipped`) so a
@@ -1,6 +1,6 @@
1
1
  import { withCurrentParams } from "./registry.ts";
2
2
 
3
- type SweepPoint<T extends Record<string, readonly unknown[]>> = {
3
+ export type SweepPoint<T extends Record<string, readonly unknown[]>> = {
4
4
  [K in keyof T]: T[K][number];
5
5
  };
6
6
 
package/src/index.ts CHANGED
@@ -6,19 +6,24 @@ export type { BenchOptions } from "./bench/index.ts";
6
6
  export { bench } from "./bench/index.ts";
7
7
  export { range } from "./bench/range.ts";
8
8
  export type { GroupOptions, TaskOptions } from "./bench/registry.ts";
9
+ export type { GroupFn, Hook, TaskFn } from "./bench/registry.ts";
9
10
  export { group, task } from "./bench/registry.ts";
11
+ export type { MeasureTasksOpts } from "./bench/run-tasks.ts";
10
12
  export type { RunOptions } from "./bench/run.ts";
11
13
  export { run } from "./bench/run.ts";
14
+ export type { SweepPoint } from "./bench/sweep.ts";
12
15
  export { sweep } from "./bench/sweep.ts";
13
16
  export type { CompareResult, Thresholds } from "./compare/index.ts";
14
17
  export { compareDocuments, DEFAULT_THRESHOLDS } from "./compare/index.ts";
15
18
  export type {
16
19
  AbConfig,
20
+ BenchConfig,
17
21
  BenchProject,
18
22
  OstiaConfig,
19
23
  OstiaConfigInput,
20
24
  WorkloadConfig,
21
25
  } from "./config/index.ts";
26
+ export { OstiaUsageError } from "./errors.ts";
22
27
  export {
23
28
  createDocument,
24
29
  loadDocument,
@@ -26,13 +31,22 @@ export {
26
31
  saveDocument,
27
32
  } from "./ir/document.ts";
28
33
  export type {
34
+ AbSummary,
35
+ ComparedTask,
29
36
  Comparison,
37
+ ComparisonSummary,
38
+ Environment,
39
+ GitMetadata,
40
+ Measurement,
41
+ PairedEvidence,
30
42
  ProfileDocument,
31
43
  Warning,
32
44
  WarningCode,
33
45
  Workload,
34
46
  } from "./ir/types.ts";
47
+ export { WARNING_CODES } from "./ir/types.ts";
35
48
  export { keep } from "./measure/inprocess.ts";
49
+ export type { Side } from "./measure/paired.ts";
36
50
  export type { ProfileOptions, ProfileResult } from "./profile.ts";
37
51
  export { profile } from "./profile.ts";
38
52
  export { renderers } from "./renderers/index.ts";
@@ -41,9 +55,12 @@ export type {
41
55
  MinimalEvent,
42
56
  MinimalProtocolContext,
43
57
  MinimalRenderOptions,
58
+ MinimalRunLine,
59
+ MinimalSummaryLine,
60
+ MinimalUnmatchedLine,
44
61
  } from "./renderers/minimal.ts";
45
62
  export { MINIMAL_PROTOCOL_VERSION } from "./renderers/minimal.ts";
46
- export type { VizOptions } from "./renderers/types.ts";
63
+ export type { FormatName, Renderer, VizOptions } from "./renderers/types.ts";
47
64
  export type {
48
65
  PrepareFn,
49
66
  PrepareHook,
package/src/ir/types.ts CHANGED
@@ -420,13 +420,13 @@ export interface AbSummary {
420
420
  verdict: "pass" | "fail";
421
421
  }
422
422
 
423
+ // compat: annotated, since Bun 1.4.6 canary's declaration build overflows
424
+ // its stack when another module imports a type taken with `typeof` from
425
+ // an unannotated array (WarningCode, below).
423
426
  /**
424
427
  * Every `Warning.code`. A runtime array so a test can assert each is
425
428
  * emitted.
426
429
  */
427
- // compat: annotated, not `as const`: Bun 1.4.6 canary's declaration
428
- // build overflows its stack when another module imports a type
429
- // derived from an `as const` array (WarningCode, below).
430
430
  export const WARNING_CODES: readonly [
431
431
  "slow-first-run",
432
432
  "outliers-detected",
@@ -98,7 +98,7 @@ interface MinimalMemoryChange {
98
98
  /**
99
99
  * One per timing run, for piping into an agent's context in place of the
100
100
  * full `ProfileDocument`. Numbers stay in the IR's units (ns). */
101
- interface MinimalRunLine {
101
+ export interface MinimalRunLine {
102
102
  event: "run";
103
103
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
104
104
  schemaVersion: ProfileDocument["schemaVersion"];
@@ -166,7 +166,7 @@ interface MinimalRunLine {
166
166
  }
167
167
 
168
168
  /** A workload present on only one side of a `compare`/`ci` run. */
169
- interface MinimalUnmatchedLine {
169
+ export interface MinimalUnmatchedLine {
170
170
  event: "unmatched";
171
171
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
172
172
  workloadId: string;
@@ -177,7 +177,7 @@ interface MinimalUnmatchedLine {
177
177
  /**
178
178
  * The last line of a `compare`/`ci`/`ab` run; never emitted for a bare
179
179
  * `time`/`bench` document. */
180
- interface MinimalSummaryLine {
180
+ export interface MinimalSummaryLine {
181
181
  event: "summary";
182
182
  protocolVersion: typeof MINIMAL_PROTOCOL_VERSION;
183
183
  command: "compare" | "ci" | "ab";