@abide/harness 0.5.0 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abide/harness",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "Ratios against hand-written code, counts of the work an op did, and gates whose revert can be run — three measurement lanes for anything that renders, on bun",
6
6
  "license": "MIT",
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "peerDependencies": {
59
59
  "@playwright/test": "^1.64.0",
60
- "@abide/abide": ">=0.140.0"
60
+ "@abide/abide": ">=0.143.0"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "@playwright/test": {
@@ -7,6 +7,11 @@
7
7
  // `__HARNESS_MEASURE__` off the page. Built in memory rather than into `dist/`: every
8
8
  // spec loads in both engine projects at once, and two workers writing one file is a
9
9
  // reader that can catch it half-written.
10
+ //
11
+ // A SCRIPT, NOT AN ENTRY: abide's browser specs import it by path, and it stays out of `exports`
12
+ // because no app measuring itself injects a lane by hand — `@abide/harness/abide`'s preload does
13
+ // that for one — so an entry would be public surface, with its clauses and its pages, for this
14
+ // repo's specs alone.
10
15
 
11
16
  import type { Page } from '@playwright/test'
12
17
 
@@ -29,8 +29,7 @@ export type Shares = {
29
29
  /**
30
30
  * The share, which is also the CPU ceiling.
31
31
  *
32
- * An optimization is capped by the fraction of the op it touches. One number, not two — the
33
- * sketch returned the fraction twice, once as `layer` and once as `ceilingCpu`.
32
+ * An optimization is capped by the fraction of the op it touches.
34
33
  */
35
34
  ceilingCpu: number
36
35
  /**
@@ -428,10 +428,9 @@ function counting(
428
428
  original: AnyFunction,
429
429
  ): AnyFunction {
430
430
  return function (this: unknown, ...args: unknown[]): unknown {
431
- // Nested inside an already-counted call: the outermost one has already said
432
- // what this op did.
433
- if (depth > 0) return original.apply(this, args)
434
- if (!armed) return original.apply(this, args)
431
+ // Nested inside an already-counted call, the outermost one has already said what this
432
+ // op did.
433
+ if (depth > 0 || !armed) return original.apply(this, args)
435
434
  depth = 1
436
435
  try {
437
436
  tallyBefore(role, this, args, member)
@@ -7,5 +7,5 @@
7
7
  // nothing itself.
8
8
 
9
9
  export { rowsCommand } from './rowsCommand.ts'
10
- export { runBenches } from './runBenches.ts'
10
+ export { type Bench, runBenches } from './runBenches.ts'
11
11
  export { type TestSuite, testRows } from './testRows.ts'
@@ -4,6 +4,21 @@ import { type Batched, claimOf, ratio } from '../report/index.ts'
4
4
  export const milliseconds = (nanoseconds: number) =>
5
5
  `${(nanoseconds / 1e6).toFixed(3)} ms`
6
6
 
7
+ /** One bench `runBenches` ran: its file, its case, and each arm's time per operation. */
8
+ export type Bench = {
9
+ file: string
10
+ name: string
11
+ case: string
12
+ n: number
13
+ floor: number
14
+ /** Nanoseconds per operation, by arm. */
15
+ arms: Record<string, number>
16
+ /** The last arm over the first, as the harness is allowed to say it; '' for one arm. */
17
+ claim: string
18
+ /** An arm over its ceiling, and a ceiling naming no arm or no bench. */
19
+ over: string[]
20
+ }
21
+
7
22
  /**
8
23
  * Every bench beside the code, `src/**\/*.bench.ts` under `root`, run in this process one after
9
24
  * another: each function a file exports is one bench, and its `CEILINGS` names the most each arm
@@ -15,21 +30,7 @@ export const milliseconds = (nanoseconds: number) =>
15
30
  export async function runBenches(
16
31
  root: string,
17
32
  only?: string,
18
- ): Promise<
19
- {
20
- file: string
21
- name: string
22
- case: string
23
- n: number
24
- floor: number
25
- /** Nanoseconds per operation, by arm. */
26
- arms: Record<string, number>
27
- /** The last arm over the first, as the harness is allowed to say it; '' for one arm. */
28
- claim: string
29
- /** An arm over its ceiling, and a ceiling naming no arm or no bench. */
30
- over: string[]
31
- }[]
32
- > {
33
+ ): Promise<Bench[]> {
33
34
  const base = root.endsWith('/') ? root : `${root}/`
34
35
  const files = [...new Bun.Glob('src/**/*.bench.ts').scanSync(base)].sort()
35
36
  const benches = []
@@ -1,4 +1,4 @@
1
- // Lane 3 of 3 — bytes, microtask turns and allocations, on bun.
1
+ // Lane 3 of 3 — bytes, microtask turns and what a run leaves reachable, on bun.
2
2
  // The lane that prices what ships and what the server spends getting it there.
3
3
  //
4
4
  // There is no `calls()` here. `bun:test` already ships one —
@@ -6,7 +6,7 @@
6
6
  // with `mockRestore` for the teardown — and a second spelling would be a rename with
7
7
  // a worse restore story.
8
8
 
9
- export { allocated } from './allocated.ts'
9
+ export { retainedPerRun } from './retainedPerRun.ts'
10
10
  export { bytes } from './bytes.ts'
11
11
  export { closures } from './closures.ts'
12
12
  export { retained } from './retained.ts'
@@ -1,5 +1,5 @@
1
1
  // Live objects by JSC type, and the change between two readings — what `retained()` and
2
- // `allocated()` both diff. Not on the lane's entry: each of the two says what its reading means.
2
+ // `retainedPerRun()` both diff. Not on the lane's entry: each of the two says what its reading means.
3
3
 
4
4
  import { fullGC, heapStats } from 'bun:jsc'
5
5
 
@@ -11,12 +11,12 @@ import { fullGC, heapStats } from 'bun:jsc'
11
11
  export function liveCounts(caller: string): Record<string, number> {
12
12
  // happy-dom's own implementation objects land in the same untyped `Object` bucket as the
13
13
  // framework's, so a total taken in a preloaded process is worthless for any op that touches
14
- // the DOM. `bunfig.toml` preloads a DOM into every `bun test` process, so the allocation gates
14
+ // the DOM. `bunfig.toml` preloads a DOM into every `bun test` process, so the reachability gates
15
15
  // get their own preload-free invocation and this converts the silent contamination into a
16
16
  // failure.
17
17
  if (typeof document !== 'undefined')
18
18
  throw new Error(
19
- `${caller}() ran in a process with a DOM. happy-dom buckets as \`Object\` exactly where the framework does, so the totals would move with the emulator. Run the allocation gates in a preload-free process.`,
19
+ `${caller}() ran in a process with a DOM. happy-dom buckets as \`Object\` exactly where the framework does, so the totals would move with the emulator. Run the reachability gates in a preload-free process.`,
20
20
  )
21
21
  fullGC()
22
22
  return heapStats().objectTypeCounts as Record<string, number>
@@ -9,8 +9,8 @@
9
9
  // collected it before the `after` read. So whether a gate observes what it gates
10
10
  // would depend on the optimizer's liveness analysis of a case body, invisible at the
11
11
  // call site and flipping when the body is edited for an unrelated reason. This
12
- // function answers the question that is stable; `allocated()` answers the other one
13
- // and is tagged so it cannot be gated on.
12
+ // function answers the question that is stable; `retainedPerRun()` answers it as a batch mean
13
+ // and is tagged so it cannot be gated on. Neither sees what an op allocated and dropped.
14
14
 
15
15
  import { countsMoved, liveCounts } from './liveCounts.ts'
16
16
 
@@ -0,0 +1,61 @@
1
+ // WHAT EACH RUN OF AN OP KEEPS, as a batch mean: the objects still reachable after a full
2
+ // collection, per run. NOT WHAT IT ALLOCATED — `heapStats()` counts survivors only, and JSC has no
3
+ // allocation counter, so an op that builds four objects and drops them reads ~0 here, and this was
4
+ // named `allocated` while it read that. Tagged, and the tag is the point: an exact integer is
5
+ // `retained()`'s to hand out, and a fractional reading like `Object:3.09` is a reachability
6
+ // artifact rather than a genuinely fractional quantity.
7
+ //
8
+ // What a fractional per-run count IS good for is the other question: a non-integer means what is
9
+ // kept is conditional or amortized — a rehash, a cache filling, a once-per-batch structure — and a
10
+ // mean over the whole batch hides which. So the batch is halved and the two halves are reported
11
+ // apart. Zero growth across them is the leak check.
12
+
13
+ import { countsMoved, liveCounts } from './liveCounts.ts'
14
+
15
+ const DEFAULT_REPS = 1000
16
+
17
+ /**
18
+ * Mean objects each rep leaves reachable, by JSC type over a batch, and how that mean grew between
19
+ * its halves.
20
+ *
21
+ * A batch mean, never exact — gate exact counts on `retained()`. Throws in a process with a DOM.
22
+ */
23
+ export function retainedPerRun(
24
+ body: () => unknown,
25
+ reps = DEFAULT_REPS,
26
+ ): {
27
+ /**
28
+ * Always `'batch mean'`.
29
+ *
30
+ * A literal, so this record can never be `toMatchObject`'d against an exact integer the way a
31
+ * `retained()` diff is.
32
+ */
33
+ tagged: 'batch mean'
34
+ reps: number
35
+ perRep: Record<string, number>
36
+ /**
37
+ * The last half's mean minus the first half's, per rep.
38
+ *
39
+ * A type that grows across the batch is retaining rather than allocating.
40
+ */
41
+ growth: Record<string, number>
42
+ } {
43
+ // EXACTLY `reps` RUNS, the second half taking an odd one — halved to equal halves, 401 ran 400.
44
+ const runs = Math.max(2, Math.floor(reps))
45
+ const firstHalf = Math.floor(runs / 2)
46
+ const secondHalf = runs - firstHalf
47
+ const start = liveCounts('retainedPerRun')
48
+ for (let rep = 0; rep < firstHalf; rep += 1) body()
49
+ const middle = liveCounts('retainedPerRun')
50
+ for (let rep = 0; rep < secondHalf; rep += 1) body()
51
+ const end = liveCounts('retainedPerRun')
52
+
53
+ const first = countsMoved(start, middle, firstHalf)
54
+ const second = countsMoved(middle, end, secondHalf)
55
+ return {
56
+ tagged: 'batch mean',
57
+ reps: runs,
58
+ perRep: countsMoved(start, end, runs),
59
+ growth: countsMoved(first, second, 1),
60
+ }
61
+ }
@@ -1,56 +0,0 @@
1
- // WHAT AN OP ALLOCATED, which `heapStats()` cannot see and this therefore does not
2
- // pretend to report exactly. A batch mean, tagged, and the tag is the point: an exact
3
- // integer is `retained()`'s to hand out, and a fractional reading like `Object:3.09`
4
- // is a reachability artifact rather than a genuinely fractional quantity.
5
- //
6
- // What a fractional per-rep count IS good for is the other question: a non-integer
7
- // means the allocation is conditional or amortized — a rehash, an IC transition, a
8
- // once-per-batch structure — and a mean over the whole batch hides which. So the
9
- // batch is halved and the two halves are reported apart. Zero growth across them is
10
- // the leak check.
11
-
12
- import { countsMoved, liveCounts } from './liveCounts.ts'
13
-
14
- const DEFAULT_REPS = 1000
15
-
16
- /**
17
- * Mean objects per rep by JSC type over a batch, and how that mean grew between its halves.
18
- *
19
- * A batch mean, never exact — gate exact counts on `retained()`. Throws in a process with a DOM.
20
- */
21
- export function allocated(
22
- body: () => unknown,
23
- reps = DEFAULT_REPS,
24
- ): {
25
- /**
26
- * Always `'batch mean'`.
27
- *
28
- * A literal, so this record can never be `toMatchObject`'d against an exact integer the way a
29
- * `retained()` diff is.
30
- */
31
- tagged: 'batch mean'
32
- reps: number
33
- perRep: Record<string, number>
34
- /**
35
- * The last half's mean minus the first half's, per rep.
36
- *
37
- * A type that grows across the batch is retaining rather than allocating.
38
- */
39
- growth: Record<string, number>
40
- } {
41
- const half = Math.max(1, Math.floor(reps / 2))
42
- const start = liveCounts('allocated')
43
- for (let rep = 0; rep < half; rep += 1) body()
44
- const middle = liveCounts('allocated')
45
- for (let rep = 0; rep < half; rep += 1) body()
46
- const end = liveCounts('allocated')
47
-
48
- const first = countsMoved(start, middle, half)
49
- const second = countsMoved(middle, end, half)
50
- return {
51
- tagged: 'batch mean',
52
- reps: half * 2,
53
- perRep: countsMoved(start, end, half * 2),
54
- growth: countsMoved(first, second, 1),
55
- }
56
- }