@ac-kit/test-util 0.4.0 → 0.5.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,73 @@
1
1
  # @ac-kit/test-util
2
2
 
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [5c203e7]
8
+ - Updated dependencies [5c203e7]
9
+ - Updated dependencies [5c203e7]
10
+ - Updated dependencies [5c203e7]
11
+ - @ac-kit/core@0.14.0
12
+
13
+ ## 0.5.0
14
+
15
+ ### Minor Changes
16
+
17
+ - 0b4fe43: `@ac-kit/test-util/v8` exports `allocatedBytesPerCall(body, options?)`: the
18
+ mean bytes one call of `body` allocates once warmed up: every byte of the
19
+ JavaScript heap's object spaces — garbage freed by collections inside the
20
+ measurement, and what the engine allocates outside any JavaScript function,
21
+ the code it compiles aside — plus every off-heap `ArrayBuffer` backing store
22
+ allocated, at its byte length. The measurement's own cost and 256 bytes a
23
+ window of engine noise are removed, so an allocation-free body reads 0 and an
24
+ allocating one at most `256 / calls` bytes low. `warmUpCalls`,
25
+ `calls` and `windows` (the least window is kept) tune it; a `RangeError`
26
+ refuses a non-integer or out-of-range count. Node only; leaves V8's
27
+ array-buffer sweeping synchronous for the rest of the process.
28
+ - 0b4fe43: `@ac-kit/test-util/v8` exports `allocatedMemoryPerCall(body, options?)`: the
29
+ measurement `allocatedBytesPerCall` makes, split into `heapBytes` (JavaScript
30
+ heap objects, garbage included) and `externalBytes` (off-heap `ArrayBuffer`
31
+ backing stores, each counted once at its byte length, freed in the measurement
32
+ or not), with their sum, `bytes`. A body that allocates no buffer reads
33
+ `externalBytes` 0, so a gate tells a typed array allocated per call from a
34
+ stray object.
35
+ - 0b4fe43: `@ac-kit/test-util/v8` exports `allocationSitesPerCall(body, options?)`: the
36
+ mean bytes one call of `body` allocates once warmed up, and the functions that
37
+ allocated them, largest first, from V8's sampling heap profiler. Garbage counts
38
+ as much as what survives, the profiler's own cost is removed, and `include`
39
+ restricts the figure to the scripts under test; what a builtin allocates is its
40
+ calling function's, and what the optimiser inlined is its caller's.
41
+ `externalBytesPerCall` adds the off-heap `ArrayBuffer` backing stores per call,
42
+ which no sample sees, outside the sites and `include`. Node only; leaves V8's
43
+ array-buffer sweeping synchronous for the rest of the process.
44
+ - 0b4fe43: `exactDotScaled(a, b)` is the reference for a dot product beyond the doubles or
45
+ below them: `Σ aᵢ·bᵢ` computed exactly in integers and rounded once to 53
46
+ significant bits, ties to even, with no bound on the exponent, as `{
47
+ significand, exponent }` (significand in `±[1, 2)`, or `0` and `0` for an
48
+ exact zero). It shares no code with what it checks, as `exactDot`.
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [0b4fe43]
53
+ - Updated dependencies [0b4fe43]
54
+ - Updated dependencies [0b4fe43]
55
+ - Updated dependencies [0b4fe43]
56
+ - Updated dependencies [0b4fe43]
57
+ - Updated dependencies [0b4fe43]
58
+ - Updated dependencies [0b4fe43]
59
+ - Updated dependencies [0b4fe43]
60
+ - Updated dependencies [0b4fe43]
61
+ - Updated dependencies [0b4fe43]
62
+ - Updated dependencies [0b4fe43]
63
+ - Updated dependencies [0b4fe43]
64
+ - Updated dependencies [0b4fe43]
65
+ - Updated dependencies [0b4fe43]
66
+ - Updated dependencies [0b4fe43]
67
+ - Updated dependencies [0b4fe43]
68
+ - Updated dependencies [0b4fe43]
69
+ - @ac-kit/core@0.13.0
70
+
3
71
  ## 0.4.0
4
72
 
5
73
  ### Minor Changes
package/README.md CHANGED
@@ -67,6 +67,12 @@ expect(Math.abs(result - exactDot(a, b))).toBeLessThanOrEqual(
67
67
  );
68
68
  ```
69
69
 
70
+ `exactDotScaled(a, b)` rounds the same exact sum to 53 significant bits with no
71
+ bound on the exponent, as `{ significand, exponent }` (significand in `±[1, 2)`,
72
+ or `0` and `0` for an exact zero): the reference for a sum beyond
73
+ `Number.MAX_VALUE` or below the subnormals, such as a cross product of huge or
74
+ tiny coordinates.
75
+
70
76
  An exact zero, or empty input, gives `+0`; a non-zero sum below half the
71
77
  smallest subnormal gives a zero of its own sign; past `Number.MAX_VALUE` after
72
78
  rounding, `±Infinity`. The functions throw a `RangeError` when the lengths
@@ -123,6 +129,45 @@ branded value always comes from its own creator, and bulk kernels with a
123
129
 
124
130
  ## `@ac-kit/test-util/v8`
125
131
 
132
+ `allocationSitesPerCall` measures what one call of a hot path allocates, by
133
+ the function that allocated it, from V8's sampling heap profiler: garbage
134
+ included, the profiler's own cost removed, and optionally restricted to the
135
+ scripts under test (a function the optimiser inlined counts as its caller's).
136
+
137
+ ```ts
138
+ import { allocationSitesPerCall } from "@ac-kit/test-util/v8";
139
+
140
+ declare const renderFrame: () => void;
141
+ const { bytesPerCall, sites } = await allocationSitesPerCall(renderFrame);
142
+ // bytesPerCall: 0 for an allocation-free path; sites: who allocates, largest first
143
+ ```
144
+
145
+ `allocatedBytesPerCall` counts everything one call allocates: the growth of the
146
+ heap's object spaces plus what every collection in the window freed, what no
147
+ JavaScript function allocated (the engine's own bookkeeping) included but not
148
+ the code the engine compiles, and the off-heap backing stores of the
149
+ `ArrayBuffer`s it allocated (a typed array over more than 64 bytes), each
150
+ counted once at its byte length, collected in the window or not. Its own cost
151
+ and 256 bytes a window of engine noise are removed, so an allocation-free body
152
+ reads 0; measure a control loop of the same shape alongside to tell the
153
+ engine's share from the code's. `allocatedMemoryPerCall` gives the same figure
154
+ split into `heapBytes` and `externalBytes`, and `allocationSitesPerCall`
155
+ reports the backing stores it cannot attribute to a site as
156
+ `externalBytesPerCall`.
157
+
158
+ ```ts
159
+ import { allocatedBytesPerCall } from "@ac-kit/test-util/v8";
160
+ import { allocatedMemoryPerCall } from "@ac-kit/test-util/v8";
161
+
162
+ declare const renderFrame: () => void;
163
+ const bytes = allocatedBytesPerCall(renderFrame, { calls: 50_000 });
164
+ const { heapBytes, externalBytes } = allocatedMemoryPerCall(renderFrame);
165
+ ```
166
+
167
+ Both make V8 free dead backing stores inside the collection that finds them
168
+ (`--no-concurrent-array-buffer-sweeping`) and expose `gc`, for the rest of the
169
+ process.
170
+
126
171
  `v8ElementsKind` reports the elements kind V8 holds for an array
127
172
  (`"packed-smi"`, `"packed-double"`, `"holey-object"`, `"dictionary"`, …), to test
128
173
  that a creator or a hot loop keeps a `number[]` on the compact kind its speed
@@ -24,6 +24,33 @@
24
24
  * or infinite: a reference must not answer a test's mistake with `NaN`.
25
25
  */
26
26
  export declare function exactDot(a: ArrayLike<number>, b: ArrayLike<number>): number;
27
+ /** {@link exactDotScaled}'s result: `significand · 2^exponent`. */
28
+ export type ScaledFloat = {
29
+ /** In `±[1, 2)`, or `0` for an exact zero. */
30
+ readonly significand: number;
31
+ /** An integer, `0` for an exact zero. */
32
+ readonly exponent: number;
33
+ };
34
+ /**
35
+ * `Σ aᵢ·bᵢ` computed exactly in integers and rounded once to 53 significant
36
+ * bits, ties to even, with no bound on the exponent: the reference for a sum
37
+ * beyond `Number.MAX_VALUE` or below the subnormals, which {@link exactDot}
38
+ * would give as `±Infinity` or a rounded subnormal. Its independence is
39
+ * {@link exactDot}'s.
40
+ *
41
+ * Time complexity: O(n) `bigint` operations, as {@link exactDot}.
42
+ *
43
+ * @example
44
+ * exactDotScaled([Number.MAX_VALUE], [4]); // { significand: 2 - 2 ** -52, exponent: 1025 }
45
+ * exactDotScaled([2 ** -1074], [2 ** -1074]); // { significand: 1, exponent: -2148 }
46
+ *
47
+ * @param a - Left factors.
48
+ * @param b - Right factors, paired by index.
49
+ * @returns The exact sum, rounded once, as significand and exponent.
50
+ * @throws {RangeError} When `a` and `b` differ in length, or an entry is `NaN`
51
+ * or infinite.
52
+ */
53
+ export declare function exactDotScaled(a: ArrayLike<number>, b: ArrayLike<number>): ScaledFloat;
27
54
  /**
28
55
  * The sign of the exact `Σ aᵢ·bᵢ`: `-1`, `0` (only an exactly zero sum, which
29
56
  * empty input is) or `1`. The reference `dotSign` is checked against, with the
@@ -1 +1 @@
1
- {"version":3,"file":"exact-d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AAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAClB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAQZ;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAC1B,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EACpB,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAClB,MAAM,CAcR"}
package/dist/exact-dot.js CHANGED
@@ -6,7 +6,7 @@ import { bitsToFloat64, float64ToBits } from "@ac-kit/core";
6
6
  * smallest exponent. The sum is rounded to binary64 once, at the end, in
7
7
  * integer code.
8
8
  *
9
- * Independence is the point (CONVENTIONS §15): what these check is built on
9
+ * Independence is the point: what these check is built on
10
10
  * `twoSumError`, `twoProductError`, `PreciseSum` and `float64ToParts`, so they
11
11
  * use none of them. The decomposition below duplicates core's on purpose, and
12
12
  * the only core functions called are `float64ToBits` and `bitsToFloat64`,
@@ -114,6 +114,60 @@ export function exactDot(a, b) {
114
114
  }
115
115
  return assemble_(isNegative, kept, resultExponent);
116
116
  }
117
+ /**
118
+ * `Σ aᵢ·bᵢ` computed exactly in integers and rounded once to 53 significant
119
+ * bits, ties to even, with no bound on the exponent: the reference for a sum
120
+ * beyond `Number.MAX_VALUE` or below the subnormals, which {@link exactDot}
121
+ * would give as `±Infinity` or a rounded subnormal. Its independence is
122
+ * {@link exactDot}'s.
123
+ *
124
+ * Time complexity: O(n) `bigint` operations, as {@link exactDot}.
125
+ *
126
+ * @example
127
+ * exactDotScaled([Number.MAX_VALUE], [4]); // { significand: 2 - 2 ** -52, exponent: 1025 }
128
+ * exactDotScaled([2 ** -1074], [2 ** -1074]); // { significand: 1, exponent: -2148 }
129
+ *
130
+ * @param a - Left factors.
131
+ * @param b - Right factors, paired by index.
132
+ * @returns The exact sum, rounded once, as significand and exponent.
133
+ * @throws {RangeError} When `a` and `b` differ in length, or an entry is `NaN`
134
+ * or infinite.
135
+ */
136
+ export function exactDotScaled(a, b) {
137
+ const { mantissa: units, exponent } = exactSum_(a, b, "exactDotScaled");
138
+ if (units === 0n) {
139
+ return { significand: 0, exponent: 0 };
140
+ }
141
+ const isNegative = units < 0n;
142
+ const magnitude = isNegative ? -units : units;
143
+ const bitLength = magnitude.toString(2).length;
144
+ // The unit of the last place of the 53 bits kept.
145
+ let unitExponent = bitLength - 53 + exponent;
146
+ const dropped = bitLength - 53;
147
+ let kept;
148
+ if (dropped <= 0) {
149
+ kept = magnitude << BigInt(-dropped);
150
+ }
151
+ else {
152
+ const shift = BigInt(dropped);
153
+ kept = magnitude >> shift;
154
+ const remainder = magnitude - (kept << shift);
155
+ const half = 1n << (shift - 1n);
156
+ if (remainder > half || (remainder === half && (kept & 1n) === 1n)) {
157
+ kept += 1n;
158
+ }
159
+ }
160
+ if (kept === HIDDEN_BIT_ << 1n) {
161
+ kept = HIDDEN_BIT_;
162
+ unitExponent += 1;
163
+ }
164
+ // `kept` is below 2⁵³, so its conversion and the scaling are exact.
165
+ const significand = Number(kept) / 2 ** 52;
166
+ return {
167
+ significand: isNegative ? -significand : significand,
168
+ exponent: unitExponent + 52,
169
+ };
170
+ }
117
171
  /** `kept · 2^exponent`, with `kept` at most `2⁵³`, as a binary64's bits. */
118
172
  function assemble_(isNegative, kept, exponent) {
119
173
  let significand = kept;
@@ -1 +1 @@
1
- {"version":3,"file":"exact-dot.js","sourceRoot":"","sources":["../src/exact-dot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5D;;;;;;;;;;;;;;GAcG;AAEH,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,cAAc,GAAG,CAAC,EAAE,IAAI,cAAc,CAAC,GAAG,EAAE,CAAC;AACnD,MAAM,WAAW,GAAG,EAAE,IAAI,cAAc,CAAC;AACzC,MAAM,SAAS,GAAG,EAAE,IAAI,GAAG,CAAC;AAC5B,4EAA4E;AAC5E,MAAM,mBAAmB,GAAG,CAAC,IAAI,CAAC;AAClC,6DA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,UAAU,CACnB,uDAAuD,CAAC,CAAC,MAAM,QAAQ,CAAC,CAAC,MAAM,EAAE,CACjF,CAAC;IACH,CAAC;IAED,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/C,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAE,GAAG,CAAC,CAAC,KAAK,CAAE,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -9,7 +9,7 @@ function show_(value) {
9
9
  return Object.is(value, -0) ? "-0" : String(value);
10
10
  }
11
11
  function expectSameNumbers_(label, actual, expected) {
12
- expect(actual.length, `${label}: length of out`).toBe(expected.length);
12
+ expect(actual).toHaveLength(expected.length);
13
13
  for (let index = 0; index < expected.length; index++) {
14
14
  if (!Object.is(actual[index], expected[index])) {
15
15
  expect.fail(`${label}: out[${index}] is ${show_(actual[index])}, a separate out gives ${show_(expected[index])}`);
@@ -1 +1 @@
1
- {"version":3,"file":"expect-alias-safe.js","sourceRoot":"","sources":["../src/expect-alias-safe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAShC,SAAS,kBAAkB,CAAC,SAAuB;IAClD,MAAM,KAAK,GACV,SAAS,CAAC,GAAG,KAAK,OAAO;QACxB,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,2BAA2B,SAAS,CAAC,GAAG,EAAE,CAAC;IAE/C,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,mCAAmC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC9E,CAAC;AAED,SAAS,KAAK,CAAC,KAAc;IAC5B,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,C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Y;QAAE,OAAO,EAAE,aAAa;KAAC,EACjD,WAAW,CACX,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,kBAAkB,CACjC,IAAI,SAAS,SAAS,CAAC,MAAM,CAAC,EAC9B,KAAK,CAAC,KAAK,SAAS,SAAS,OAAO,EAAE,EACrC,UAAU,EAAE,sBAAsB,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,YAAY,CAsE/D"}
@@ -90,9 +90,7 @@ export function defineOutFirstCase(definition) {
90
90
  }
91
91
  // The lengths are those of the arguments as built, before any sharing
92
92
  // hides a difference between them.
93
- const target = placement.out === "fresh"
94
- ? create()
95
- : built[placement.out];
93
+ const target = placement.out === "fresh" ? create() : built[placement.out];
96
94
  for (const index of aliasable) {
97
95
  const { length } = built[index];
98
96
  if (length !== target.length) {
@@ -105,11 +103,9 @@ export function defineOutFirstCase(definition) {
105
103
  for (const index of aliasable) {
106
104
  shared[index] = built[aliasable[0]];
107
105
  }
108
- args = shared;
106
+ args = shared; // shared is a copy of the argument tuple with the aliased slots pointing at one value
109
107
  }
110
- const out = placement.out === "fresh"
111
- ? target
112
- : args[placement.out];
108
+ const out = placement.out === "fresh" ? target : args[placement.out];
113
109
  return { out, returned: call(out, args) };
114
110
  },
115
111
  };
@@ -1 +1 @@
1
- {"version":3,"file":"out-first-case.js","sourceRoot":"","sources":["../src/out-first-case.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,GAGb,MAAM,cAAc,CAAC;AAQtB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,SAAS,CAAC,MAAyB;IAClD,4EAA4E;IAC5E,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEpC,OAAO,GAAG,EAAE;QACX,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,OAAO,GAAG,EAAE;YACX,IAAI,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE,C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G,IAAI,cAAc,KAAK,eAAe,MAAM,aAAa,MAAM,CAAC,MAAM,EAAE,CAC3E,CAAC;gBACH,CAAC;YACF,CAAC;YAED,IAAI,IAAI,GAAG,KAAK,CAAC;YAEjB,IAAI,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC7C,MAAM,MAAM,GAAc,CAAC,GAAG,KAAK,CAAC,CAAC;gBAErC,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;oBAC/B,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAE,CAAC,CAAC;gBACtC,CAAC;gBAED,IAAI,GAAG,MAA0B,CAAC,CAAC,sFAAsF;YAC1H,CAAC;YAED,MAAM,GAAG,GACR,SAAS,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAU,CAAC;YAEpE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;QAC3C,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ import v8 from "node:v8";
2
+ /**
3
+ * Two full collections. The first frees the garbage; its sweeping, left to
4
+ * background threads and to later allocations, still lowers the heap's used
5
+ * size after it returns, so a window opened then would read less than it
6
+ * allocated. The second finishes that sweeping before it starts and finds next
7
+ * to nothing to free, so what its own sweeping leaves is about nothing.
8
+ */
9
+ export declare function collect_(): void;
10
+ /** Used bytes of the spaces objects live in, now. */
11
+ export declare function objectHeapUsed_(): number;
12
+ /** What the collections inside one window freed. */
13
+ export type WindowCollections_ = {
14
+ /** Bytes of the spaces objects live in. */
15
+ readonly heapFreed: number;
16
+ /** External bytes: `ArrayBuffer` backing stores and the embedder's. */
17
+ readonly externalFreed: number;
18
+ /**
19
+ * Whether one of them sweeps after it ends, so `heapFreed` may fall short of
20
+ * what it freed.
21
+ */
22
+ readonly sweptAfter: boolean;
23
+ };
24
+ export declare function windowCollections_(profile: v8.GCProfilerResult): WindowCollections_;
25
+ //# sourceMappingURL=_collect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_collect.d.ts","sourceRoot":"","sources":["../../src/v8/_collect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,SAAS,CAAC;AA4BzB;;;;;;GAMG;AACH,wBAAgB,QAAQ,IAAI,IAAI,CAI/B;AAkBD,qDAAqD;AACrD,wBAAgB,eAAe,IAAI,MAAM,CAUxC;AAwBD,oDAAoD;AACpD,MAAM,MAAM,kBAAkB,GAAG;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uEAAuE;IACvE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,EAAE,CAAC,gBAAgB,GAC1B,kBAAkB,CAiBpB"}
@@ -0,0 +1,94 @@
1
+ /// <reference types="node" />
2
+ import v8 from "node:v8";
3
+ import vm from "node:vm";
4
+ let gc_;
5
+ /**
6
+ * Prepares the process for counting: exposes `gc`, and makes V8 free the
7
+ * backing stores of dead `ArrayBuffer`s inside the collection that found them
8
+ * dead (`--no-concurrent-array-buffer-sweeping`), so what a collection frees is
9
+ * visible in its own before and after statistics rather than later, on a
10
+ * background thread, outside any collection. Both flags stay set for the rest
11
+ * of the process: V8 cannot report a flag's previous value to restore it.
12
+ */
13
+ function prepare_() {
14
+ v8.setFlagsFromString("--no-concurrent-array-buffer-sweeping");
15
+ const exposed = globalThis.gc;
16
+ if (typeof exposed === "function") {
17
+ return exposed;
18
+ }
19
+ // The flag only adds `gc` to contexts created after it is set.
20
+ v8.setFlagsFromString("--expose-gc");
21
+ return vm.runInNewContext("gc");
22
+ }
23
+ /**
24
+ * Two full collections. The first frees the garbage; its sweeping, left to
25
+ * background threads and to later allocations, still lowers the heap's used
26
+ * size after it returns, so a window opened then would read less than it
27
+ * allocated. The second finishes that sweeping before it starts and finds next
28
+ * to nothing to free, so what its own sweeping leaves is about nothing.
29
+ */
30
+ export function collect_() {
31
+ gc_ ??= prepare_();
32
+ gc_();
33
+ gc_();
34
+ }
35
+ /**
36
+ * Spaces where V8 keeps what it compiles — machine code, bytecode, feedback
37
+ * metadata — and the read-only snapshot, rather than the objects a program
38
+ * allocates. What they gain or lose in a window is the engine tiering code up
39
+ * or sweeping code it collected, not an allocation of the code under test.
40
+ */
41
+ const CODE_SPACES_ = new Set([
42
+ "read_only_space",
43
+ "code_space",
44
+ "code_large_object_space",
45
+ "trusted_space",
46
+ "trusted_large_object_space",
47
+ "shared_trusted_space",
48
+ "shared_trusted_large_object_space",
49
+ ]);
50
+ /** Used bytes of the spaces objects live in, now. */
51
+ export function objectHeapUsed_() {
52
+ let used = 0;
53
+ for (const space of v8.getHeapSpaceStatistics()) {
54
+ if (!CODE_SPACES_.has(space.space_name)) {
55
+ used += space.space_used_size;
56
+ }
57
+ }
58
+ return used;
59
+ }
60
+ function objectSpacesUsed_(spaces) {
61
+ let used = 0;
62
+ for (const space of spaces) {
63
+ if (!CODE_SPACES_.has(space.spaceName)) {
64
+ used += space.spaceUsedSize;
65
+ }
66
+ }
67
+ return used;
68
+ }
69
+ /**
70
+ * Collection kinds after which sweeping goes on outside the collection: the
71
+ * heap's used size keeps dropping after them, by garbage their statistics do
72
+ * not show as freed.
73
+ */
74
+ const SWEEPING_COLLECTIONS_ = new Set([
75
+ "MarkSweepCompact",
76
+ "MinorMarkSweep",
77
+ ]);
78
+ export function windowCollections_(profile) {
79
+ let heapFreed = 0;
80
+ let externalFreed = 0;
81
+ let sweptAfter = false;
82
+ for (const collection of profile.statistics) {
83
+ const { beforeGC, afterGC } = collection;
84
+ heapFreed +=
85
+ objectSpacesUsed_(beforeGC.heapSpaceStatistics) -
86
+ objectSpacesUsed_(afterGC.heapSpaceStatistics);
87
+ externalFreed +=
88
+ beforeGC.heapStatistics.externalMemory -
89
+ afterGC.heapStatistics.externalMemory;
90
+ sweptAfter ||= SWEEPING_COLLECTIONS_.has(collection.gcType);
91
+ }
92
+ return { heapFreed, externalFreed, sweptAfter };
93
+ }
94
+ //# sourceMappingURL=_collect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_collect.js","sourceRoot":"","sources":["../../src/v8/_collect.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AAIzB,IAAI,GAA+B,CAAC;AAEpC;;;;;;;GAOG;AACH,SAAS,QAAQ;IAChB,EAAE,CAAC,kBAAkB,CAAC,uCAAuC,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAI,UAAsC,CAAC,EAAE,CAAC;IAE3D,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QACnC,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,+DAA+D;IAC/D,EAAE,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC;IACrC,OAAO,EAAE,CAAC,eAAe,CAAC,IAAI,CAAmB,CAAC;AACnD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ;IACvB,GAAG,KAAK,QAAQ,EAAE,CAAC;IACnB,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;AACP,CAAC;AAED;;;;;GAKG;AACH,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC;IACjD,iBAAiB;IACjB,YAAY;IACZ,yBAAyB;IACzB,eAAe;IACf,4BAA4B;IAC5B,sBAAsB;IACtB,mCAAmC;CACnC,CAAC,CAAC;AAEH,qDAAqD;AACrD,MAAM,UAAU,eAAe;IAC9B,IAAI,IAAI,GAAG,CAAC,CAAC;IAEb,KAAK,MAAM,KAAK,IAAI,EAAE,CAAC,sBAAs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D,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { type CallableNoArgs } from "@ac-kit/core";
2
+ export type AllocatedBytesOptions = {
3
+ /**
4
+ * Calls made before measuring, so the engine has optimised `body` and every
5
+ * buffer it grows has reached its working size. Default 10 000; an integer ≥ 0.
6
+ */
7
+ readonly warmUpCalls?: number;
8
+ /** Calls per measured window. Default 10 000; an integer ≥ 1. */
9
+ readonly calls?: number;
10
+ /**
11
+ * Measured windows; the least is kept, so a window in which the engine was
12
+ * still compiling `body` (code and feedback live in the heap too) does not
13
+ * count. Default 5; an integer ≥ 1.
14
+ */
15
+ readonly windows?: number;
16
+ };
17
+ /** What {@link allocatedMemoryPerCall} found: mean bytes per call, by kind. */
18
+ export type AllocatedMemory = {
19
+ /** `heapBytes + externalBytes`. */
20
+ readonly bytes: number;
21
+ /**
22
+ * JavaScript heap bytes: every object, array, closure, string, boxed number
23
+ * and elements store, a typed array's own object and an on-heap backing store
24
+ * (64 bytes or fewer) included, and what the engine allocates on the heap
25
+ * outside any JavaScript function; not the compiled code, bytecode and
26
+ * feedback metadata of the engine's code spaces.
27
+ */
28
+ readonly heapBytes: number;
29
+ /**
30
+ * Off-heap bytes V8 accounts as external: the backing stores of the
31
+ * `ArrayBuffer`s and `SharedArrayBuffer`s allocated (those of typed arrays
32
+ * and `DataView`s over more than 64 bytes, `Buffer`s), and memory the
33
+ * embedder reports to V8 as external.
34
+ */
35
+ readonly externalBytes: number;
36
+ };
37
+ /**
38
+ * Mean bytes one call of `body` allocates once warmed up, on the JavaScript
39
+ * heap and off it, for asserting that a hot path allocates nothing and, when it
40
+ * does, telling objects from buffers.
41
+ *
42
+ * Each window starts from two full collections and runs `calls` calls of `body`
43
+ * under `v8.GCProfiler`:
44
+ *
45
+ * - `heapBytes` is the growth of the spaces objects live in (new, old and
46
+ * large-object spaces) plus what every collection inside the window freed of
47
+ * them, so garbage is counted to the byte. The spaces of compiled code,
48
+ * bytecode and feedback metadata are left out: what they gain or lose in a
49
+ * window is the engine tiering code up, or sweeping code it collected, not
50
+ * what `body` allocates. A mark-compact collection goes on sweeping after it
51
+ * ends, freeing garbage its statistics do not show, so a window one ran in is
52
+ * measured again with half the calls, down to one call; a body that runs one
53
+ * in a single call reads low by what it swept. The measurement's own cost,
54
+ * the median of empty windows, is removed, and so are 256 bytes a window,
55
+ * what the engine's feedback and inline-cache updates around the loop add to
56
+ * it whatever the number of calls: a body that allocates nothing reads 0, and
57
+ * one that allocates reads at most `256 / calls` bytes low.
58
+ * - `externalBytes` is the growth of V8's external memory plus what every
59
+ * collection inside the window freed of it: each `ArrayBuffer` backing store
60
+ * counts once, at its byte length, when it is allocated, collected in the
61
+ * window or not. V8 is set to free dead backing stores inside the collection
62
+ * that finds them (`--no-concurrent-array-buffer-sweeping`) so that a
63
+ * collection's statistics show what it freed. A body that allocates no buffer
64
+ * reads 0; memory the embedder releases outside a collection (a native
65
+ * resource closed in `body`) offsets what `body` allocates, and the figure is
66
+ * then a lower bound.
67
+ *
68
+ * A backing store of 64 bytes or fewer lives on the heap, in `heapBytes`. The
69
+ * least of `windows` windows by `bytes` is kept, so the figure is the steady
70
+ * state rather than the engine still compiling. Never negative.
71
+ *
72
+ * What it shows is the engine's behaviour on this run: a body the engine has
73
+ * not optimised, or whose callers' inlining budget differs, may allocate where
74
+ * it otherwise would not (a double crossing a call that is not inlined is
75
+ * boxed). Warm it up as the code under test is warmed up in use.
76
+ *
77
+ * Node only (`node:v8`). Exposes `gc` to new contexts when the process was
78
+ * started without `--expose-gc`, and leaves array-buffer sweeping synchronous
79
+ * for the rest of the process. Runs `warmUpCalls + windows · calls` calls of
80
+ * `body`, more when sweeping collections run in a window.
81
+ *
82
+ * @throws {RangeError} `warmUpCalls` not an integer ≥ 0, `calls` or `windows`
83
+ * not an integer ≥ 1.
84
+ */
85
+ export declare function allocatedMemoryPerCall(body: CallableNoArgs, options?: AllocatedBytesOptions): AllocatedMemory;
86
+ /**
87
+ * Mean bytes one call of `body` allocates once warmed up, on the JavaScript
88
+ * heap and off it (`ArrayBuffer` backing stores included), for asserting that a
89
+ * hot path allocates nothing: the `bytes` of {@link allocatedMemoryPerCall},
90
+ * which tells the two apart and documents what is counted. A body that
91
+ * allocates nothing reads 0.
92
+ *
93
+ * @throws {RangeError} `warmUpCalls` not an integer ≥ 0, `calls` or `windows`
94
+ * not an integer ≥ 1.
95
+ */
96
+ export declare function allocatedBytesPerCall(body: CallableNoArgs, options?: AllocatedBytesOptions): number;
97
+ //# sourceMappingURL=allocated-bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allocated-bytes.d.ts","sourceRoot":"","sources":["../../src/v8/allocated-bytes.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAIlE,MAAM,MAAM,qBAAqB,GAAG;IACnC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,iEAAiE;IACjE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GAAG;IAC7B,mCAAmC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAC/B,CAAC;AAyHF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,qBAA0B,GACjC,eAAe,CAEjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,qBAA0B,GACjC,MAAM,CAER"}
@@ -0,0 +1,148 @@
1
+ /// <reference types="node" />
2
+ import v8 from "node:v8";
3
+ import { assertInteger } from "@ac-kit/core";
4
+ import { collect_, objectHeapUsed_, windowCollections_ } from "./_collect.js";
5
+ /** Empty windows whose median is the measurement's own cost. */
6
+ const CALIBRATION_WINDOWS_ = 9;
7
+ /**
8
+ * What a window of a body that allocates nothing reads above the cost, at most:
9
+ * the engine updating feedback and inline caches around the measuring loop, a
10
+ * few to a few hundred bytes a window whatever the number of calls (measured on
11
+ * Node 24 and 26). It is removed from every window with the cost.
12
+ */
13
+ const WINDOW_NOISE_BYTES_ = 256;
14
+ /**
15
+ * Bytes allocated by `calls` calls of `body` (none when `calls` is 0), the
16
+ * measurement's own bookkeeping included.
17
+ */
18
+ function measureWindow_(profiler, body, calls) {
19
+ collect_();
20
+ profiler.start();
21
+ const heapStart = objectHeapUsed_();
22
+ const externalStart = v8.getHeapStatistics().external_memory;
23
+ for (let call = 0; call < calls; call++) {
24
+ body();
25
+ }
26
+ // Read before `stop`, which builds the report outside the window.
27
+ const externalEnd = v8.getHeapStatistics().external_memory;
28
+ const heapEnd = objectHeapUsed_();
29
+ const { heapFreed, externalFreed, sweptAfter } = windowCollections_(profiler.stop());
30
+ // What a collection freed was counted as used at the start or allocated in
31
+ // the window; either way growth plus the freed bytes is the allocation.
32
+ return {
33
+ heap: heapEnd - heapStart + heapFreed,
34
+ external: externalEnd - externalStart + externalFreed,
35
+ sweptAfter,
36
+ };
37
+ }
38
+ function measure_(name, body, options) {
39
+ const { warmUpCalls = 10000, calls = 10000, windows = 5 } = options;
40
+ assertInteger(warmUpCalls, `${name}: warmUpCalls`, 0);
41
+ assertInteger(calls, `${name}: calls`, 1);
42
+ assertInteger(windows, `${name}: windows`, 1);
43
+ const profiler = new v8.GCProfiler();
44
+ // Through the measuring loop itself, so that loop is optimised too. The
45
+ // window starts with full collections, so code that embedded objects which
46
+ // died before the call is deoptimized and re-optimised during the warm-up,
47
+ // not inside a measured window.
48
+ measureWindow_(profiler, body, warmUpCalls);
49
+ const heapCosts = [];
50
+ const externalCosts = [];
51
+ for (let window = 0; window < CALIBRATION_WINDOWS_; window++) {
52
+ const empty = measureWindow_(profiler, body, 0);
53
+ heapCosts.push(empty.heap);
54
+ externalCosts.push(empty.external);
55
+ }
56
+ const heapCost = median_(heapCosts);
57
+ const externalCost = median_(externalCosts);
58
+ let least;
59
+ for (let window = 0; window < windows; window++) {
60
+ let windowCalls = calls;
61
+ let measured = measureWindow_(profiler, body, windowCalls);
62
+ // A window a sweeping collection ran in may read low: it is measured
63
+ // again with half the calls until none runs in it, or one call does.
64
+ while (measured.sweptAfter && windowCalls > 1) {
65
+ windowCalls = Math.ceil(windowCalls / 2);
66
+ measured = measureWindow_(profiler, body, windowCalls);
67
+ }
68
+ const heapBytes = Math.max(0, measured.heap - heapCost - WINDOW_NOISE_BYTES_) / windowCalls;
69
+ const externalBytes = Math.max(0, measured.external - externalCost) / windowCalls;
70
+ const bytes = heapBytes + externalBytes;
71
+ if (least === undefined || bytes < least.bytes) {
72
+ least = { bytes, heapBytes, externalBytes };
73
+ }
74
+ }
75
+ return least;
76
+ }
77
+ function median_(values) {
78
+ values.sort((first, second) => first - second);
79
+ const middle = values.length >> 1;
80
+ return values.length % 2 === 1
81
+ ? values[middle]
82
+ : (values[middle - 1] + values[middle]) / 2;
83
+ }
84
+ /**
85
+ * Mean bytes one call of `body` allocates once warmed up, on the JavaScript
86
+ * heap and off it, for asserting that a hot path allocates nothing and, when it
87
+ * does, telling objects from buffers.
88
+ *
89
+ * Each window starts from two full collections and runs `calls` calls of `body`
90
+ * under `v8.GCProfiler`:
91
+ *
92
+ * - `heapBytes` is the growth of the spaces objects live in (new, old and
93
+ * large-object spaces) plus what every collection inside the window freed of
94
+ * them, so garbage is counted to the byte. The spaces of compiled code,
95
+ * bytecode and feedback metadata are left out: what they gain or lose in a
96
+ * window is the engine tiering code up, or sweeping code it collected, not
97
+ * what `body` allocates. A mark-compact collection goes on sweeping after it
98
+ * ends, freeing garbage its statistics do not show, so a window one ran in is
99
+ * measured again with half the calls, down to one call; a body that runs one
100
+ * in a single call reads low by what it swept. The measurement's own cost,
101
+ * the median of empty windows, is removed, and so are 256 bytes a window,
102
+ * what the engine's feedback and inline-cache updates around the loop add to
103
+ * it whatever the number of calls: a body that allocates nothing reads 0, and
104
+ * one that allocates reads at most `256 / calls` bytes low.
105
+ * - `externalBytes` is the growth of V8's external memory plus what every
106
+ * collection inside the window freed of it: each `ArrayBuffer` backing store
107
+ * counts once, at its byte length, when it is allocated, collected in the
108
+ * window or not. V8 is set to free dead backing stores inside the collection
109
+ * that finds them (`--no-concurrent-array-buffer-sweeping`) so that a
110
+ * collection's statistics show what it freed. A body that allocates no buffer
111
+ * reads 0; memory the embedder releases outside a collection (a native
112
+ * resource closed in `body`) offsets what `body` allocates, and the figure is
113
+ * then a lower bound.
114
+ *
115
+ * A backing store of 64 bytes or fewer lives on the heap, in `heapBytes`. The
116
+ * least of `windows` windows by `bytes` is kept, so the figure is the steady
117
+ * state rather than the engine still compiling. Never negative.
118
+ *
119
+ * What it shows is the engine's behaviour on this run: a body the engine has
120
+ * not optimised, or whose callers' inlining budget differs, may allocate where
121
+ * it otherwise would not (a double crossing a call that is not inlined is
122
+ * boxed). Warm it up as the code under test is warmed up in use.
123
+ *
124
+ * Node only (`node:v8`). Exposes `gc` to new contexts when the process was
125
+ * started without `--expose-gc`, and leaves array-buffer sweeping synchronous
126
+ * for the rest of the process. Runs `warmUpCalls + windows · calls` calls of
127
+ * `body`, more when sweeping collections run in a window.
128
+ *
129
+ * @throws {RangeError} `warmUpCalls` not an integer ≥ 0, `calls` or `windows`
130
+ * not an integer ≥ 1.
131
+ */
132
+ export function allocatedMemoryPerCall(body, options = {}) {
133
+ return measure_("allocatedMemoryPerCall", body, options);
134
+ }
135
+ /**
136
+ * Mean bytes one call of `body` allocates once warmed up, on the JavaScript
137
+ * heap and off it (`ArrayBuffer` backing stores included), for asserting that a
138
+ * hot path allocates nothing: the `bytes` of {@link allocatedMemoryPerCall},
139
+ * which tells the two apart and documents what is counted. A body that
140
+ * allocates nothing reads 0.
141
+ *
142
+ * @throws {RangeError} `warmUpCalls` not an integer ≥ 0, `calls` or `windows`
143
+ * not an integer ≥ 1.
144
+ */
145
+ export function allocatedBytesPerCall(body, options = {}) {
146
+ return measure_("allocatedBytesPerCall", body, options).bytes;
147
+ }
148
+ //# sourceMappingURL=allocated-bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allocated-bytes.js","sourceRoot":"","sources":["../../src/v8/allocated-bytes.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,aAAa,EAAuB,MAAM,cAAc,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAuC9E,gEAAgE;AAChE,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAahC;;;GAGG;AACH,SAAS,cAAc,CACtB,QAAuB,EACvB,IAAoB,EACpB,KAAa;IAEb,QAAQ,EAAE,CAAC;IACX,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;IACpC,MAAM,aAAa,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC,eAAe,CAAC;IAE7D,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;QACzC,IAAI,EAAE,CAAC;IACR,CAAC;IAED,kEAAkE;IAClE,MAAM,WAAW,GAAG,EAAE,CAAC,iBAAiB,EAAE,CAAC,eAAe,CAAC;IAC3D,MAAM,OAAO,GAAG,eAAe,EAAE,CAAC;IAClC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,kBAAkB,CAClE,QAAQ,CAAC,IAAI,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AAG,CAAC,KAAK,CAAC;QAC7B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAE;QACjB,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAE,GAAG,MAAM,CAAC,MAAM,CAAE,CAAC,GAAG,CAAC,CAAC;AAChD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,UAAU,sBAAsB,CACrC,IAAoB,EACpB,OAAO,GAA0B,EAAE;IAEnC,OAAO,QAAQ,CAAC,wBAAwB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CACpC,IAAoB,EACpB,OAAO,GAA0B,EAAE;IAEnC,OAAO,QAAQ,CAAC,uBAAuB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,92 @@
1
+ import { type Callable, type CallableNoArgs } from "@ac-kit/core";
2
+ export type AllocationSitesOptions = {
3
+ /**
4
+ * Calls made before sampling, so the engine has optimised `body`. Default 10
5
+ * 000; an integer ≥ 0.
6
+ */
7
+ readonly warmUpCalls?: number;
8
+ /** Calls sampled. Default 10 000; an integer ≥ 1. */
9
+ readonly calls?: number;
10
+ /**
11
+ * Mean bytes between two samples (V8 draws the gaps from a Poisson
12
+ * distribution). Default 16; an integer ≥ 1.
13
+ */
14
+ readonly samplingInterval?: number;
15
+ /**
16
+ * Whether allocations made by a function of the script at `url` count.
17
+ * Default every function's.
18
+ */
19
+ readonly include?: Callable<[url: string], boolean>;
20
+ };
21
+ /**
22
+ * Where `body`'s calls allocated: one function, as V8 names it. What a builtin
23
+ * (`Array`, `slice`, a typed-array constructor) allocates is the script
24
+ * function's that called it.
25
+ */
26
+ export type AllocationSite = {
27
+ readonly functionName: string;
28
+ /**
29
+ * The URL of the function's script; `""` for what no script function
30
+ * allocated.
31
+ */
32
+ readonly url: string;
33
+ /** 1-based. */
34
+ readonly line: number;
35
+ /** Mean bytes it allocated per call of `body`. */
36
+ readonly bytesPerCall: number;
37
+ };
38
+ export type AllocationSites = {
39
+ /** Mean bytes per call of `body` over the sites that count. */
40
+ readonly bytesPerCall: number;
41
+ /** The sites that count, largest first. */
42
+ readonly sites: readonly AllocationSite[];
43
+ /**
44
+ * Mean off-heap bytes per call of `body` V8 accounts as external, which the
45
+ * sampling profiler does not see: `ArrayBuffer` and `SharedArrayBuffer`
46
+ * backing stores (those of typed arrays and `DataView`s over more than 64
47
+ * bytes, `Buffer`s) and memory the embedder reports to V8, counted as
48
+ * {@link allocatedMemoryPerCall} counts its `externalBytes`. It belongs to no
49
+ * site, `include` does not restrict it, and `bytesPerCall` leaves it out; the
50
+ * backing store's buffer and typed-array objects are on the heap, in a site.
51
+ */
52
+ readonly externalBytesPerCall: number;
53
+ };
54
+ /**
55
+ * Mean bytes one call of `body` allocates once warmed up, by the function that
56
+ * allocated them, from V8's sampling heap profiler: what to look at when
57
+ * {@link allocatedBytesPerCall} reads more than nothing, and a measurement that
58
+ * `include` restricts to the code under test, leaving out what the engine, the
59
+ * runtime or the test runner allocate meanwhile (compiled code, feedback,
60
+ * timers).
61
+ *
62
+ * Every object, array, closure, string or boxed number a JavaScript function
63
+ * allocates is sampled, collected or not; what the engine allocates outside any
64
+ * JavaScript function is not. A site is the function V8 sees on the stack: a
65
+ * function the optimiser inlined allocates in its caller's name, so `include`
66
+ * can leave out what an excluded caller inlined — leave `include` out to
67
+ * measure everything `body` allocates. The figure is statistical: about one
68
+ * sample every `samplingInterval` bytes, so allocations of a few bytes per call
69
+ * need many calls. The profiler's own cost, an empty window sampled the same
70
+ * way, is removed site by site, so a body that allocates nothing reads about 0.
71
+ * Backing stores are off the heap and no sample sees them:
72
+ * `externalBytesPerCall` counts them, every window starting from two full
73
+ * collections, as {@link allocatedMemoryPerCall} does; a gate checks both. A
74
+ * full collection also runs before the warm-up, so code that embedded objects
75
+ * which died before the call is deoptimized and re-optimised during the
76
+ * warm-up, not inside the window.
77
+ *
78
+ * Node only (`node:inspector`, `node:v8`). Exposes `gc` to new contexts when
79
+ * the process was started without `--expose-gc`, and leaves array-buffer
80
+ * sweeping synchronous for the rest of the process. Runs `warmUpCalls + calls`
81
+ * calls of `body`.
82
+ *
83
+ * @example
84
+ * const { bytesPerCall, sites } = await allocationSitesPerCall(render, {
85
+ * include: (url) => url.includes("/packages/"),
86
+ * });
87
+ *
88
+ * @throws {RangeError} `warmUpCalls` not an integer ≥ 0, `calls` or
89
+ * `samplingInterval` not an integer ≥ 1.
90
+ */
91
+ export declare function allocationSitesPerCall(body: CallableNoArgs, options?: AllocationSitesOptions): Promise<AllocationSites>;
92
+ //# sourceMappingURL=allocation-sites.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allocation-sites.d.ts","sourceRoot":"","sources":["../../src/v8/allocation-sites.ts"],"names":[],"mappings":"AAIA,OAAO,EAEN,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,MAAM,cAAc,CAAC;AAItB,MAAM,MAAM,sBAAsB,GAAG;IACpC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,qDAAqD;IACrD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;CACpD,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,eAAe;IACf,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC7B,+DAA+D;IAC/D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,CAAC;IAC1C;;;;;;;;OAQG;IACH,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;CACtC,CAAC;AAkFF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAsB,sBAAsB,CAC3C,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,sBAA2B,GAClC,OAAO,CAAC,eAAe,CAAC,CA+D1B"}
@@ -0,0 +1,131 @@
1
+ /// <reference types="node" />
2
+ import { Session } from "node:inspector/promises";
3
+ import v8 from "node:v8";
4
+ import { assertInteger, } from "@ac-kit/core";
5
+ import { collect_, windowCollections_ } from "./_collect.js";
6
+ /**
7
+ * Bytes sampled per site key over `calls` calls of `body`, and the external
8
+ * bytes they allocated.
9
+ */
10
+ async function sampleWindow_(session, profiler, body, calls, samplingInterval, include) {
11
+ const parameters = {
12
+ samplingInterval,
13
+ // garbage counts as much as what survives
14
+ includeObjectsCollectedByMinorGC: true,
15
+ includeObjectsCollectedByMajorGC: true,
16
+ };
17
+ collect_();
18
+ await session.post("HeapProfiler.startSampling", parameters);
19
+ profiler.start();
20
+ const start = process.memoryUsage().external;
21
+ for (let call = 0; call < calls; call++) {
22
+ body();
23
+ }
24
+ const end = process.memoryUsage().external;
25
+ const { externalFreed } = windowCollections_(profiler.stop());
26
+ const { profile } = await session.post("HeapProfiler.stopSampling");
27
+ const sites = new Map();
28
+ const visit = (node, caller) => {
29
+ // a builtin (`Array`, `slice`) allocates for the script function that
30
+ // called it: the sample goes to the innermost frame with a script
31
+ const frame = node.callFrame.url === "" ? caller : node.callFrame;
32
+ const { functionName, url, lineNumber } = frame;
33
+ if (node.selfSize > 0 && (include === undefined || include(url))) {
34
+ const key = `${url}:${lineNumber}:${functionName}`;
35
+ const entry = sites.get(key);
36
+ if (entry === undefined) {
37
+ sites.set(key, {
38
+ site: { functionName, url, line: lineNumber + 1 },
39
+ bytes: node.selfSize,
40
+ });
41
+ }
42
+ else {
43
+ entry.bytes += node.selfSize;
44
+ }
45
+ }
46
+ for (const child of node.children) {
47
+ visit(child, frame);
48
+ }
49
+ };
50
+ const head = profile.head; // the sampling profile's head node has the SampledNode_ shape, which the V8 typings omit
51
+ visit(head, head.callFrame);
52
+ return { sites, external: end - start + externalFreed };
53
+ }
54
+ /**
55
+ * Mean bytes one call of `body` allocates once warmed up, by the function that
56
+ * allocated them, from V8's sampling heap profiler: what to look at when
57
+ * {@link allocatedBytesPerCall} reads more than nothing, and a measurement that
58
+ * `include` restricts to the code under test, leaving out what the engine, the
59
+ * runtime or the test runner allocate meanwhile (compiled code, feedback,
60
+ * timers).
61
+ *
62
+ * Every object, array, closure, string or boxed number a JavaScript function
63
+ * allocates is sampled, collected or not; what the engine allocates outside any
64
+ * JavaScript function is not. A site is the function V8 sees on the stack: a
65
+ * function the optimiser inlined allocates in its caller's name, so `include`
66
+ * can leave out what an excluded caller inlined — leave `include` out to
67
+ * measure everything `body` allocates. The figure is statistical: about one
68
+ * sample every `samplingInterval` bytes, so allocations of a few bytes per call
69
+ * need many calls. The profiler's own cost, an empty window sampled the same
70
+ * way, is removed site by site, so a body that allocates nothing reads about 0.
71
+ * Backing stores are off the heap and no sample sees them:
72
+ * `externalBytesPerCall` counts them, every window starting from two full
73
+ * collections, as {@link allocatedMemoryPerCall} does; a gate checks both. A
74
+ * full collection also runs before the warm-up, so code that embedded objects
75
+ * which died before the call is deoptimized and re-optimised during the
76
+ * warm-up, not inside the window.
77
+ *
78
+ * Node only (`node:inspector`, `node:v8`). Exposes `gc` to new contexts when
79
+ * the process was started without `--expose-gc`, and leaves array-buffer
80
+ * sweeping synchronous for the rest of the process. Runs `warmUpCalls + calls`
81
+ * calls of `body`.
82
+ *
83
+ * @example
84
+ * const { bytesPerCall, sites } = await allocationSitesPerCall(render, {
85
+ * include: (url) => url.includes("/packages/"),
86
+ * });
87
+ *
88
+ * @throws {RangeError} `warmUpCalls` not an integer ≥ 0, `calls` or
89
+ * `samplingInterval` not an integer ≥ 1.
90
+ */
91
+ export async function allocationSitesPerCall(body, options = {}) {
92
+ const { warmUpCalls = 10000, calls = 10000, samplingInterval = 16, include, } = options;
93
+ assertInteger(warmUpCalls, "allocationSitesPerCall: warmUpCalls", 0);
94
+ assertInteger(calls, "allocationSitesPerCall: calls", 1);
95
+ assertInteger(samplingInterval, "allocationSitesPerCall: samplingInterval", 1);
96
+ // a full collection first, so code that embedded objects which died before
97
+ // the call is deoptimized and re-optimised during the warm-up, not inside the
98
+ // window
99
+ collect_();
100
+ for (let call = 0; call < warmUpCalls; call++) {
101
+ body();
102
+ }
103
+ const session = new Session();
104
+ session.connect();
105
+ try {
106
+ await session.post("HeapProfiler.enable");
107
+ const profiler = new v8.GCProfiler();
108
+ const cost = await sampleWindow_(session, profiler, body, 0, samplingInterval, include);
109
+ const measured = await sampleWindow_(session, profiler, body, calls, samplingInterval, include);
110
+ await session.post("HeapProfiler.disable");
111
+ const sites = [];
112
+ let total = 0;
113
+ for (const [key, { site, bytes }] of measured.sites) {
114
+ const own = Math.max(0, bytes - (cost.sites.get(key)?.bytes ?? 0));
115
+ if (own > 0) {
116
+ total += own;
117
+ sites.push({ ...site, bytesPerCall: own / calls });
118
+ }
119
+ }
120
+ sites.sort((first, second) => second.bytesPerCall - first.bytesPerCall);
121
+ return {
122
+ bytesPerCall: total / calls,
123
+ sites,
124
+ externalBytesPerCall: Math.max(0, measured.external - cost.external) / calls,
125
+ };
126
+ }
127
+ finally {
128
+ session.disconnect();
129
+ }
130
+ }
131
+ //# sourceMappingURL=allocation-sites.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allocation-sites.js","sourceRoot":"","sources":["../../src/v8/allocation-sites.ts"],"names":[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AAG,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;YACnE,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;gBACb,KAAK,IAAI,GAAG,CAAC;gBACb,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,YAAY,EAAE,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC;YACpD,CAAC;QACF,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;QACxE,OAAO;YACN,YAAY,EAAE,KAAK,GAAG,KAAK;YAC3B,KAAK;YACL,oBAAoB,EACnB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,KAAK;SACvD,CAAC;IACH,CAAC;YAAS,CAAC;QACV,OAAO,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;AACF,CAAC"}
@@ -1,2 +1,4 @@
1
+ export * from "./allocated-bytes.js";
2
+ export * from "./allocation-sites.js";
1
3
  export * from "./elements-kind.js";
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/v8/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/v8/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
package/dist/v8/index.js CHANGED
@@ -1,2 +1,4 @@
1
+ export * from "./allocated-bytes.js";
2
+ export * from "./allocation-sites.js";
1
3
  export * from "./elements-kind.js";
2
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v8/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v8/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ac-kit/test-util",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "Dependency-free test-harness primitives, such as a deterministic synchronous delay for timing-sensitive tests.",
5
5
  "keywords": [
6
6
  "test-utils",
@@ -45,12 +45,12 @@
45
45
  "prepack": "yarn build"
46
46
  },
47
47
  "dependencies": {
48
- "@ac-kit/core": "^0.12.0"
48
+ "@ac-kit/core": "^0.14.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@ac-kit/tsconfig": "0.1.0",
52
52
  "@ac-kit/typedoc-config": "0.1.0",
53
- "@ac-kit/vitest-config": "0.2.0",
53
+ "@ac-kit/vitest-config": "0.3.0",
54
54
  "@types/node": "26.6.11",
55
55
  "@typescript/native": "typescript@7.0.2",
56
56
  "rimraf": "6.1.4",