@abide/harness 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abide/harness",
3
- "version": "0.5.0",
3
+ "version": "0.6.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.142.0"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "@playwright/test": {
@@ -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
- }