@zakkster/lite-signal 1.4.4 → 1.4.5
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 +61 -0
- package/Signal.d.ts +9 -0
- package/Signal.js +182 -9
- package/llms.txt +28 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,67 @@ All notable changes to `@zakkster/lite-signal` are documented here.
|
|
|
4
4
|
Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
5
5
|
This project follows [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.4.5] -- 2026-08-18
|
|
8
|
+
|
|
9
|
+
The createRegistry validation patch. Until now `createRegistry(config)` read five
|
|
10
|
+
options and validated none of them -- 20 of 25 malformed configs built without a
|
|
11
|
+
word and the rest failed later, deep in the node allocator, naming an internal
|
|
12
|
+
`nextFree` field rather than the option you got wrong. This closes the door. All
|
|
13
|
+
of it is constructor-cold: **the engine's hot path is byte-for-byte unchanged and
|
|
14
|
+
the zero-GC steady state does not move** (read/set/flush allocate 0 B/op as before).
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- **`prealloc:"eager"` with an absurd capacity no longer kills the process.**
|
|
19
|
+
`{maxNodes: Infinity}` and `{maxNodes: 1e9}` (a plausible typo for `1e5`) used to
|
|
20
|
+
run an unbounded construction loop and SIGABRT the process with an uncatchable
|
|
21
|
+
"Ineffective mark-compacts near heap limit" -- not a throw, so `try/catch` could
|
|
22
|
+
not see it and a supervisor got a crashed worker instead of an error. Eager
|
|
23
|
+
construction now refuses by name above a `(maxNodes + maxLinks) > (1 << 24)`
|
|
24
|
+
ceiling, throwing a `TypeError` prefixed `createRegistry: "maxNodes"` (or
|
|
25
|
+
`"maxLinks"`) that suggests `prealloc:"lazy"` for an unbounded on-demand ledger.
|
|
26
|
+
- **Fractional and non-positive capacities are rejected at construction.**
|
|
27
|
+
`{maxNodes: -1}`, `0`, `null`, `NaN` used to build a registry that died on first
|
|
28
|
+
use with `TypeError: Cannot read properties of undefined (reading 'nextFree')`;
|
|
29
|
+
`{maxNodes: 1.5}` was accepted and surfaced later as a `CapacityError`. All now
|
|
30
|
+
throw `createRegistry: "maxNodes"` (finite integer >= 1) at the call that made
|
|
31
|
+
the mistake.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- **Every option is validated by name.** `maxNodes` / `maxLinks` / `maxFlushPasses`
|
|
36
|
+
must be finite integers >= 1; `prealloc` exactly `"eager"` or `"lazy"`;
|
|
37
|
+
`onCapacityExceeded` exactly `"throw"` or `"grow"`; `config` itself a plain object
|
|
38
|
+
or `undefined` (`null`, `42`, `"eager"` are rejected). A bad value throws a
|
|
39
|
+
`TypeError` prefixed `createRegistry: "<option>"`.
|
|
40
|
+
- **Unknown keys throw with a did-you-mean hint.** `{maxNods: 32}` and
|
|
41
|
+
`{preAlloc: "lazy"}` used to build a default registry and run -- the misspelled
|
|
42
|
+
key silently ignored, so the capacity or the population strategy you asked for
|
|
43
|
+
never took effect. They now throw and suggest the intended key. If you had a typo,
|
|
44
|
+
you will now hear about it at construction instead of debugging it as production
|
|
45
|
+
jitter. A one-character `prealloc` typo in particular used to flip an eager pool
|
|
46
|
+
to lazy silently, selling back the zero-GC latency contract eager exists to buy.
|
|
47
|
+
- **`stats()` returns 13 keys** (was 11): adds `nodePoolPopulation` and
|
|
48
|
+
`linkPoolPopulation`, the PHYSICAL count of constructed pool objects, distinct
|
|
49
|
+
from the `*Capacity` ledgers. Under `"eager"` population equals capacity; under
|
|
50
|
+
`"lazy"` it starts at 0 and grows on demand. This is the instrument that lets a
|
|
51
|
+
caller confirm an eager pool actually preallocated -- previously `stats()`
|
|
52
|
+
reported only the ledger and was blind to a `prealloc` typo. No existing key
|
|
53
|
+
removed or changed; two free array-length reads, no allocation.
|
|
54
|
+
|
|
55
|
+
### Tests
|
|
56
|
+
|
|
57
|
+
- `test/28-config-validation.test.mjs` -- the full 25-config matrix: every
|
|
58
|
+
malformed row throws a `TypeError` naming the option (never reaching the internal
|
|
59
|
+
`nextFree` path), every accepted row is explicitly listed, plus the retained
|
|
60
|
+
heap-delta / population check that `"eager"` at `maxNodes:200000` retains >20 MB
|
|
61
|
+
with `nodePoolPopulation === 200000` and `"lazy"` retains ~0 with
|
|
62
|
+
`nodePoolPopulation === 0`.
|
|
63
|
+
- `test/28-config-oom.child.mjs` -- the three OOM rows (`maxNodes:Infinity`,
|
|
64
|
+
`maxNodes:1e9`, `maxLinks:Infinity`) run as isolated child processes under
|
|
65
|
+
`--max-old-space-size=256`, each asserting a caught named `TypeError` and a clean
|
|
66
|
+
exit (the fix must not SIGABRT).
|
|
67
|
+
|
|
7
68
|
## [1.4.4] -- 2026-08-03
|
|
8
69
|
|
|
9
70
|
The verification-surface patch, round four. **The engine is unchanged**: as in
|
package/Signal.d.ts
CHANGED
|
@@ -90,6 +90,15 @@ export interface RegistryStats {
|
|
|
90
90
|
/** Node-pool capacity ledger. Doubles under the `"grow"` policy; under `"lazy"`
|
|
91
91
|
* prealloc it may exceed the count of physically constructed nodes. */
|
|
92
92
|
nodePoolCapacity: number;
|
|
93
|
+
/** Physical count of node objects actually constructed in this registry (1.4.5).
|
|
94
|
+
* Under `"eager"` this equals `nodePoolCapacity`; under `"lazy"` it starts at 0
|
|
95
|
+
* and grows on demand. Distinguishes a real eager pool from a `prealloc` typo
|
|
96
|
+
* that silently fell through to lazy. */
|
|
97
|
+
nodePoolPopulation: number;
|
|
98
|
+
/** Physical count of link objects actually constructed in this registry (1.4.5).
|
|
99
|
+
* Under `"eager"` this equals `linkPoolCapacity`; under `"lazy"` it starts at 0
|
|
100
|
+
* and grows on demand. */
|
|
101
|
+
linkPoolPopulation: number;
|
|
93
102
|
/** Number of nodes currently allocated (signals + computeds + alive effects). */
|
|
94
103
|
activeNodes: number;
|
|
95
104
|
/**
|
package/Signal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @zakkster/lite-signal v1.4.
|
|
2
|
+
* @zakkster/lite-signal v1.4.5
|
|
3
3
|
* --------------------
|
|
4
4
|
* Hybrid Doubly-Linked-List Reactive Graph Engine -- decoupled (Signal1_3) base
|
|
5
5
|
* with the two 1.1.3 performance fixes ported in:
|
|
@@ -173,6 +173,88 @@ export class CapacityError extends Error {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
/** The only config keys {@link createRegistry} recognizes. Anything else is
|
|
177
|
+
* rejected at construction with a did-you-mean hint (fail closed on an
|
|
178
|
+
* unverified state -- an unknown key is an error, never a silent ignore). */
|
|
179
|
+
const ALLOWED_KEYS = ["maxNodes", "maxLinks", "prealloc", "onCapacityExceeded", "maxFlushPasses"];
|
|
180
|
+
|
|
181
|
+
/** Ceiling on eager pool construction: `(maxNodes + maxLinks)` objects. A finite
|
|
182
|
+
* but absurd `maxNodes` (e.g. `1e9`, a plausible typo for `1e5`) that would
|
|
183
|
+
* otherwise OOM the process is refused BY NAME at construction rather than
|
|
184
|
+
* allocating forever. Only the `"eager"` path is bounded; `"lazy"` keeps its
|
|
185
|
+
* unbounded ledger. `1 << 24` == 16777216. */
|
|
186
|
+
const EAGER_CONSTRUCT_CEILING = 1 << 24;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Levenshtein edit distance between two short strings. Cold: called only on the
|
|
190
|
+
* constructor error path, over the five known option names, so its per-call
|
|
191
|
+
* array allocation never touches any hot path.
|
|
192
|
+
* @param {string} a
|
|
193
|
+
* @param {string} b
|
|
194
|
+
* @returns {number}
|
|
195
|
+
*/
|
|
196
|
+
function editDistance(a, b) {
|
|
197
|
+
const m = a.length;
|
|
198
|
+
const n = b.length;
|
|
199
|
+
const prev = new Array(n + 1);
|
|
200
|
+
const cur = new Array(n + 1);
|
|
201
|
+
for (let j = 0; j <= n; j++) prev[j] = j;
|
|
202
|
+
for (let i = 1; i <= m; i++) {
|
|
203
|
+
cur[0] = i;
|
|
204
|
+
for (let j = 1; j <= n; j++) {
|
|
205
|
+
const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
|
|
206
|
+
let min = prev[j] + 1;
|
|
207
|
+
if (cur[j - 1] + 1 < min) min = cur[j - 1] + 1;
|
|
208
|
+
if (prev[j - 1] + cost < min) min = prev[j - 1] + cost;
|
|
209
|
+
cur[j] = min;
|
|
210
|
+
}
|
|
211
|
+
for (let j = 0; j <= n; j++) prev[j] = cur[j];
|
|
212
|
+
}
|
|
213
|
+
return prev[n];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The closest known config key to `key` within edit distance 2 (case-folded so
|
|
218
|
+
* `preAlloc`/`MAXNODES` resolve), or null when nothing is close. Cold path only.
|
|
219
|
+
* @param {string} key
|
|
220
|
+
* @returns {string|null}
|
|
221
|
+
*/
|
|
222
|
+
function suggestKey(key) {
|
|
223
|
+
const lk = key.toLowerCase();
|
|
224
|
+
let best = null;
|
|
225
|
+
let bestD = 3;
|
|
226
|
+
for (let i = 0; i < ALLOWED_KEYS.length; i++) {
|
|
227
|
+
const d = editDistance(lk, ALLOWED_KEYS[i].toLowerCase());
|
|
228
|
+
if (d < bestD) { bestD = d; best = ALLOWED_KEYS[i]; }
|
|
229
|
+
}
|
|
230
|
+
return bestD <= 2 ? best : null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Render a rejected value for an error message, e.g. `42 (number)`.
|
|
235
|
+
* Cold: this runs only on a throw path, never on any hot path. `String(symbol)`
|
|
236
|
+
* throws, so symbols are stringified defensively.
|
|
237
|
+
* @param {*} v
|
|
238
|
+
* @returns {string}
|
|
239
|
+
*/
|
|
240
|
+
function received(v) {
|
|
241
|
+
return (typeof v === "symbol" ? v.toString() : String(v)) + " (" + typeof v + ")";
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Validate that a numeric option is a finite integer >= 1. Cold: constructor
|
|
246
|
+
* error path only. Throws a {@link TypeError} prefixed `createRegistry: "<name>"`.
|
|
247
|
+
* @param {*} v
|
|
248
|
+
* @param {string} name
|
|
249
|
+
*/
|
|
250
|
+
function requirePositiveInt(v, name) {
|
|
251
|
+
if (!Number.isInteger(v) || v < 1) {
|
|
252
|
+
throw new TypeError(
|
|
253
|
+
'createRegistry: "' + name + '" must be a finite integer >= 1, received ' + received(v) + '.'
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
176
258
|
/**
|
|
177
259
|
* Create an isolated reactive registry.
|
|
178
260
|
*
|
|
@@ -211,18 +293,96 @@ export function createRegistry(config) {
|
|
|
211
293
|
const NODE_PTR = Symbol("node_ptr");
|
|
212
294
|
const NODE_GEN = Symbol("node_gen");
|
|
213
295
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
296
|
+
// Config-shape gate (cold). Accept `undefined` or a non-null, non-array
|
|
297
|
+
// object; reject `null`, `42`, `"eager"`, arrays and every other non-object
|
|
298
|
+
// BY NAME rather than dying later on `config.maxNodes` / an internal
|
|
299
|
+
// `nextFree` read.
|
|
300
|
+
if (config !== undefined && (config === null || typeof config !== "object" || Array.isArray(config))) {
|
|
301
|
+
throw new TypeError(
|
|
302
|
+
'createRegistry: "config" must be a plain object or undefined, received ' + received(config) + '.'
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Per-option validation (cold). Each option is validated BY NAME so a bad
|
|
307
|
+
// value throws `createRegistry: "<option>"` at construction, not a delayed
|
|
308
|
+
// internal TypeError on first use. All of this is constructor-cold: zero
|
|
309
|
+
// hot-path bytes.
|
|
310
|
+
let currentNodesCapacity = 1024;
|
|
311
|
+
let currentLinkCapacity;
|
|
312
|
+
let policy = "throw";
|
|
313
|
+
let maxFlushPasses = 100;
|
|
314
|
+
let prealloc = "eager";
|
|
315
|
+
if (config !== undefined) {
|
|
316
|
+
if (config.maxNodes !== undefined) {
|
|
317
|
+
requirePositiveInt(config.maxNodes, "maxNodes");
|
|
318
|
+
currentNodesCapacity = config.maxNodes;
|
|
319
|
+
}
|
|
320
|
+
currentLinkCapacity = currentNodesCapacity * 4;
|
|
321
|
+
if (config.maxLinks !== undefined) {
|
|
322
|
+
requirePositiveInt(config.maxLinks, "maxLinks");
|
|
323
|
+
currentLinkCapacity = config.maxLinks;
|
|
324
|
+
}
|
|
325
|
+
if (config.maxFlushPasses !== undefined) {
|
|
326
|
+
requirePositiveInt(config.maxFlushPasses, "maxFlushPasses");
|
|
327
|
+
maxFlushPasses = config.maxFlushPasses;
|
|
328
|
+
}
|
|
329
|
+
if (config.prealloc !== undefined) {
|
|
330
|
+
if (config.prealloc !== "eager" && config.prealloc !== "lazy") {
|
|
331
|
+
throw new TypeError(
|
|
332
|
+
'createRegistry: "prealloc" must be "eager" or "lazy", received ' + received(config.prealloc) + '.'
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
prealloc = config.prealloc;
|
|
336
|
+
}
|
|
337
|
+
if (config.onCapacityExceeded !== undefined) {
|
|
338
|
+
if (config.onCapacityExceeded !== "throw" && config.onCapacityExceeded !== "grow") {
|
|
339
|
+
throw new TypeError(
|
|
340
|
+
'createRegistry: "onCapacityExceeded" must be "throw" or "grow", received ' + received(config.onCapacityExceeded) + '.'
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
policy = config.onCapacityExceeded;
|
|
344
|
+
}
|
|
345
|
+
// Unknown-key rejection with a did-you-mean hint (`preAlloc` -> `prealloc`,
|
|
346
|
+
// `maxNods` -> `maxNodes`). Own enumerable keys only; cold path.
|
|
347
|
+
const keys = Object.keys(config);
|
|
348
|
+
for (let i = 0; i < keys.length; i++) {
|
|
349
|
+
const k = keys[i];
|
|
350
|
+
if (ALLOWED_KEYS.indexOf(k) === -1) {
|
|
351
|
+
const hint = suggestKey(k);
|
|
352
|
+
throw new TypeError(
|
|
353
|
+
'createRegistry: "' + k + '" is not a recognized option' +
|
|
354
|
+
(hint !== null ? ' (did you mean "' + hint + '"?)' : '') +
|
|
355
|
+
'. Allowed: ' + ALLOWED_KEYS.join(", ") + '.'
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
currentLinkCapacity = currentNodesCapacity * 4;
|
|
361
|
+
}
|
|
218
362
|
const maxLinkLimit = currentLinkCapacity * 16;
|
|
219
363
|
|
|
364
|
+
// Eager-construction ceiling (cold). `"eager"` builds `(maxNodes + maxLinks)`
|
|
365
|
+
// objects up front; a finite-but-absurd capacity (e.g. `1e9`) would OOM the
|
|
366
|
+
// process with an uncatchable SIGABRT, not a throw. Refuse BY NAME before
|
|
367
|
+
// allocating. Named for the larger driver so the message satisfies the
|
|
368
|
+
// per-option regex. `"lazy"` keeps its unbounded ledger (untouched).
|
|
369
|
+
if (prealloc === "eager" && (currentNodesCapacity + currentLinkCapacity) > EAGER_CONSTRUCT_CEILING) {
|
|
370
|
+
const driver = currentLinkCapacity > currentNodesCapacity ? "maxLinks" : "maxNodes";
|
|
371
|
+
throw new TypeError(
|
|
372
|
+
'createRegistry: "' + driver + '" eager construction of ' +
|
|
373
|
+
(currentNodesCapacity + currentLinkCapacity) + ' objects (maxNodes ' +
|
|
374
|
+
currentNodesCapacity + ' + maxLinks ' + currentLinkCapacity + ') exceeds the ceiling of ' +
|
|
375
|
+
EAGER_CONSTRUCT_CEILING + '. Use prealloc:"lazy" for an unbounded on-demand ledger, ' +
|
|
376
|
+
'or lower the capacity.'
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
220
380
|
// Lazy pool population (P1): maxNodes / maxLinks are capacity ledgers,
|
|
221
381
|
// not eager construction counts. Nodes/links are constructed on first
|
|
222
382
|
// demand and recycled through the free lists thereafter -- the zero-GC
|
|
223
383
|
// steady state is identical after warm-up, but the heap no longer carries
|
|
224
384
|
// never-used live objects for every major GC to mark.
|
|
225
|
-
|
|
385
|
+
// `prealloc` was validated and resolved above (config-cold).
|
|
226
386
|
const nodePool = [];
|
|
227
387
|
let freeNodeHead = null;
|
|
228
388
|
const linkPool = [];
|
|
@@ -1331,10 +1491,14 @@ export function createRegistry(config) {
|
|
|
1331
1491
|
* Snapshot of registry counters. Useful for diagnostics and tests --
|
|
1332
1492
|
* e.g. asserting that `activeNodes` returns to a baseline after teardown.
|
|
1333
1493
|
*
|
|
1334
|
-
* Returns
|
|
1494
|
+
* Returns 13 keys: ten live gauges (`signals`, `computeds`, `effects`,
|
|
1335
1495
|
* `activeNodes`, `activeLinks`, `pooledLinks`, `nodePoolCapacity`,
|
|
1336
|
-
* `linkPoolCapacity
|
|
1337
|
-
*
|
|
1496
|
+
* `linkPoolCapacity`, plus `nodePoolPopulation` / `linkPoolPopulation` added
|
|
1497
|
+
* in 1.4.5 -- the PHYSICAL count of constructed pool objects, which under
|
|
1498
|
+
* `"eager"` equals capacity and under `"lazy"` starts at 0 and grows on
|
|
1499
|
+
* demand, so a caller can tell a real eager pool from a `prealloc` typo that
|
|
1500
|
+
* silently fell through to lazy) plus three cumulative lifecycle counters
|
|
1501
|
+
* added in 1.4.0 (`totalAllocations`, `totalDisposals`, `poolGrowths`). The counters are
|
|
1338
1502
|
* monotonic over the registry's life and reset only by {@link destroy}; sample
|
|
1339
1503
|
* them over time to derive allocation rate, pool-reuse ratio, and graph churn
|
|
1340
1504
|
* without the engine computing rates itself. In a quiescent registry
|
|
@@ -1350,6 +1514,15 @@ export function createRegistry(config) {
|
|
|
1350
1514
|
pooledLinks: currentLinkCapacity - activeLinks,
|
|
1351
1515
|
linkPoolCapacity: currentLinkCapacity,
|
|
1352
1516
|
nodePoolCapacity: currentNodesCapacity,
|
|
1517
|
+
// 1.4.5: PHYSICAL population (constructed objects), distinct from the
|
|
1518
|
+
// capacity ledger above. `nodePool.length` / `linkPool.length` are the
|
|
1519
|
+
// exact count ever constructed in this registry: eager fills the pool to
|
|
1520
|
+
// capacity at construction (population === capacity), lazy starts at 0 and
|
|
1521
|
+
// grows on demand. This is the instrument that distinguishes a real eager
|
|
1522
|
+
// pool from a `prealloc` typo silently falling through to lazy. Two free
|
|
1523
|
+
// array-length reads, no allocation.
|
|
1524
|
+
nodePoolPopulation: nodePool.length,
|
|
1525
|
+
linkPoolPopulation: linkPool.length,
|
|
1353
1526
|
activeNodes,
|
|
1354
1527
|
// 1.4: cumulative lifecycle counters (monotonic; reset by destroy()).
|
|
1355
1528
|
// Derive: allocationRate = deltatotalAllocations/deltat; poolReuseRate =
|
package/llms.txt
CHANGED
|
@@ -22,7 +22,7 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
|
|
|
22
22
|
- **isTracking**: `isTracking()` returns true iff a read right now would record a dependency on this registry (for wrappers that lazily allocate signals).
|
|
23
23
|
- **onCleanup**: registers teardown for the current computation; fires before each re-run and once on dispose. Works in effects and computeds.
|
|
24
24
|
- **Observer-lifecycle introspection** (1.1.4; top-level + per-registry): `hasObservers(handle)` returns true iff a signal/computed has >=1 live observer right now (O(1); a `peek` does not count). `observeObservers(handle, { onConnect?, onDisconnect? })` fires on the 0->1 and 1->0 observer transitions (after registration; transition-only) and returns an idempotent unobserve -- the auto-pause hook for tickers (lite-time/lite-raf start a source only while it's watched). `forEachObserver(handle, fn)` / `forEachSource(handle, fn)` walk the live graph in either direction, passing a `{ kind, value }` descriptor (`kind` is `"signal" | "computed" | "effect"`) -- for inspection (lite-devtools). The surface is gated by an internal counter: zero steady-state cost when nothing is observed. `hasObservers`/`forEach*` no-op on a non-handle; `observeObservers` throws `TypeError`. **Node identity (1.1.5):** `nodeId(handle)` returns the node's stable per-allocation id, `describe(handle)` returns the handle's own `{ id, kind, value }` descriptor, and `forEach*` descriptors now carry `id` too; a descriptor is **re-walkable** (pass it back into `forEachObserver`/`forEachSource`) -- the recursion primitive lite-devtools uses to walk the full DAG. **Owner-tree introspection (1.2.1):** `forEachOwned(handle, fn)` walks a node's owned children (lifetime-binding edges from the 1.2 owner tree -- invisible through dep/sub); `ownerOf(handle)` returns the owner's descriptor or `undefined` for top-level / stale handles. **Stale-handle guard (1.2.1):** the entire introspection surface plus `peek()`/`read()`/`set()` is now generation-checked. A handle held across the 1.2 owner-cascade auto-dispose used to resolve `NODE_PTR` ungated and silently report the recycled slot's NEW resident; 1.2.1 surfaces stale handles as `undefined` (or `TypeError`, for `observeObservers`) -- same ABA discipline `dispose()` always had. Descriptors are gen-stamped so the re-walkable contract survives the guard. **Push-based mutation hook (1.2.1):** `onGraphMutation(fn)` registers a single nullable listener invoked synchronously at every mutation point with three integers `(opcode, intA, intB)` -- opcodes `1` node-create / `2` node-dispose / `3` link-add / `4` link-remove / `5` recompute. Zero-cost gate when no listener is registered (one branch-predicted null check); allocation-free dispatch when registered. The connection point for push-based devtools/studio. Contract: observe only -- never throw, never mutate.
|
|
25
|
-
- **Registry**: `createRegistry({ maxNodes, maxLinks, prealloc, onCapacityExceeded, maxFlushPasses })` creates an isolated reactive world with its own pools. Useful for tests, plugins, multi-tenant sandboxes. Top-level helpers use a default registry created at module load. `prealloc` (1.3.0; `"eager"` default | `"lazy"`) chooses up-front vs on-demand pool construction; `onCapacityExceeded` (`"throw"` default | `"grow"`) chooses fail-fast vs chunked-incremental growth bounded by the 16x link ceiling.
|
|
25
|
+
- **Registry**: `createRegistry({ maxNodes, maxLinks, prealloc, onCapacityExceeded, maxFlushPasses })` creates an isolated reactive world with its own pools. Useful for tests, plugins, multi-tenant sandboxes. Top-level helpers use a default registry created at module load. `prealloc` (1.3.0; `"eager"` default | `"lazy"`) chooses up-front vs on-demand pool construction; `onCapacityExceeded` (`"throw"` default | `"grow"`) chooses fail-fast vs chunked-incremental growth bounded by the 16x link ceiling. **Config is validated (1.4.5):** `maxNodes`/`maxLinks`/`maxFlushPasses` must be finite integers >= 1, `prealloc` exactly `"eager"`/`"lazy"`, `onCapacityExceeded` exactly `"throw"`/`"grow"`, `config` itself an object or undefined; a bad value throws a `TypeError` prefixed `createRegistry: "<option>"`, an unknown key throws with a did-you-mean hint, and `prealloc:"eager"` above a `1<<24`-object ceiling throws by name rather than OOM-killing the process.
|
|
26
26
|
- **CapacityError**: thrown when a fixed-size pool is exhausted under the `"throw"` policy, or when a `"grow"` policy hits the 16× starting-capacity ceiling on links.
|
|
27
27
|
|
|
28
28
|
## Architecture invariants
|
|
@@ -50,7 +50,30 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
|
|
|
50
50
|
|
|
51
51
|
## Version notes
|
|
52
52
|
|
|
53
|
-
- **1.4.
|
|
53
|
+
- **1.4.5** (current): the **createRegistry validation patch**. `createRegistry`
|
|
54
|
+
read five options and validated none of them: 20 of 25 malformed configs built
|
|
55
|
+
without complaint and the rest failed later, deep in the allocator. This closes
|
|
56
|
+
the door. `maxNodes`/`maxLinks`/`maxFlushPasses` must be finite integers >= 1;
|
|
57
|
+
`prealloc` exactly `"eager"`/`"lazy"`; `onCapacityExceeded` exactly
|
|
58
|
+
`"throw"`/`"grow"`; `config` itself an object or `undefined`. A bad value throws
|
|
59
|
+
a `TypeError` prefixed `createRegistry: "<option>"`, and an unknown key throws
|
|
60
|
+
with a did-you-mean hint (`preAlloc` -> `prealloc`, `maxNods` -> `maxNodes`)
|
|
61
|
+
instead of being silently ignored. Two severe fixes: `prealloc:"eager"` with a
|
|
62
|
+
finite-but-absurd capacity (`maxNodes:1e9`, `Infinity`) used to allocate forever
|
|
63
|
+
and SIGABRT the process uncatchably -- it now throws by name above a
|
|
64
|
+
`(maxNodes+maxLinks) > (1<<24)` ceiling before constructing anything (suggesting
|
|
65
|
+
`prealloc:"lazy"`); and a one-character `prealloc` typo used to silently flip an
|
|
66
|
+
eager pool to lazy, selling back the zero-GC real-time contract with `stats()`
|
|
67
|
+
blind to it. `stats()` now returns **13 keys** -- adds `nodePoolPopulation` /
|
|
68
|
+
`linkPoolPopulation` (physical constructed-object counts, eager == capacity,
|
|
69
|
+
lazy grows from 0), the instrument a caller reaches for to confirm the flip did
|
|
70
|
+
not happen. If you had a typo you will now hear about it at construction. **All
|
|
71
|
+
validation is constructor-cold: zero hot-path bytes, the zero-GC steady state is
|
|
72
|
+
byte-for-byte unchanged.** Tests: adds `test/28-config-validation.test.mjs` (the
|
|
73
|
+
full 25-config matrix) and `test/28-config-oom.child.mjs` (the OOM rows as
|
|
74
|
+
isolated child processes under `--max-old-space-size=256`, asserting a caught
|
|
75
|
+
named `TypeError` and a clean exit).
|
|
76
|
+
- **1.4.4**: the **verification-surface patch, round four**. No engine
|
|
54
77
|
change -- as in 1.4.1/1.4.2/1.4.3, the only edit to `Signal.js` is the banner
|
|
55
78
|
version string, `Signal.d.ts` is untouched, and `bench/torture/` stays out of
|
|
56
79
|
`files[]`; for consumers 1.4.4 is byte-for-byte 1.4.3 plus a version number. It
|
|
@@ -471,7 +494,7 @@ interface RegistryConfig {
|
|
|
471
494
|
onCapacityExceeded?: "throw" | "grow"; // default "throw"; "grow" = chunked refill, ledger doubles, 16x link ceiling
|
|
472
495
|
}
|
|
473
496
|
|
|
474
|
-
interface RegistryStats { //
|
|
497
|
+
interface RegistryStats { // 13 keys as of 1.4.5
|
|
475
498
|
signals: number;
|
|
476
499
|
computeds: number;
|
|
477
500
|
effects: number;
|
|
@@ -479,6 +502,8 @@ interface RegistryStats { // 11 keys as of 1.4.0
|
|
|
479
502
|
pooledLinks: number;
|
|
480
503
|
linkPoolCapacity: number; // ledger; doubles under "grow"
|
|
481
504
|
nodePoolCapacity: number; // ledger; doubles under "grow"
|
|
505
|
+
nodePoolPopulation: number; // 1.4.5: physical node objects constructed; eager == capacity, lazy grows from 0
|
|
506
|
+
linkPoolPopulation: number; // 1.4.5: physical link objects constructed; eager == capacity, lazy grows from 0
|
|
482
507
|
activeNodes: number; // live gauge
|
|
483
508
|
totalAllocations: number; // 1.4.0: cumulative node acquires; reset by destroy()
|
|
484
509
|
totalDisposals: number; // 1.4.0: cumulative node disposals; totalAllocations - totalDisposals === activeNodes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakkster/lite-signal",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Zero-GC reactive graph. Monomorphic object pool, versioned push-pull propagation, 32-bit modular versioning. Built for hot paths and long-running processes.",
|
|
5
5
|
"author": "Zahary Shinikchiev <shinikchiev@yahoo.com>",
|
|
6
6
|
"license": "MIT",
|