@zakkster/lite-signal 1.5.0-rc.1 → 1.5.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/CHANGELOG.md +131 -44
- package/README.md +15 -9
- package/Signal.d.ts +10 -0
- package/Signal.js +145 -1
- package/llms.txt +50 -25
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,44 +4,122 @@ 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.5.0] -- 2026-08-21
|
|
8
|
+
|
|
9
|
+
**Stable 1.5.0.** Graduates `1.5.0-rc.3` to the release line with **no further engine
|
|
10
|
+
change** -- `Signal.js` / `Signal.d.ts` are byte-identical to rc.3 past the version
|
|
11
|
+
header, and the zero-GC gates (`bench/torture/run.mjs` 22/22) are unchanged. This is
|
|
12
|
+
the first stable to carry the **1.4.5 `createRegistry` input validation** (folded in
|
|
13
|
+
at rc.3; see below) on top of the 1.5.0 surface: `signalBox` / `computedBox`,
|
|
14
|
+
`createRoot`, and `getOwner` / `runWithOwner`. Drop-in over 1.4.5 for the callable
|
|
15
|
+
API; the only observable delta on existing code is `stats()` growing 11 -> 13 keys
|
|
16
|
+
(purely additive). The full rc/beta history is retained below.
|
|
17
|
+
|
|
18
|
+
## [1.5.0-rc.3] -- 2026-08-20
|
|
19
|
+
|
|
20
|
+
Backports the **1.4.5 `createRegistry` input validation** (all four findings) onto
|
|
21
|
+
the rc.2 engine. This is the first engine change since the RC line began -- the hot
|
|
22
|
+
paths are still byte-identical to 1.4.0; only `createRegistry`'s *cold* construction
|
|
23
|
+
path gained validation, so the zero-GC gates (`bench/torture/run.mjs` 22/22) are
|
|
24
|
+
unchanged. If you had a typo in your registry config, you will now hear about it.
|
|
25
|
+
|
|
26
|
+
### Added -- createRegistry validates its config (fail closed)
|
|
27
|
+
|
|
28
|
+
- **Bounded eager construction.** `prealloc:"eager"` with a non-finite or absurd
|
|
29
|
+
capacity (`maxNodes:Infinity`, `maxNodes:1e9`) previously ran an unbounded
|
|
30
|
+
construction loop and killed the process with an **uncatchable SIGABRT**. It now
|
|
31
|
+
throws a `TypeError` **by name**, before allocating, gated on `(maxNodes+maxLinks)`
|
|
32
|
+
against a ceiling of `1<<24` (16,777,216) objects. `prealloc:"lazy"` keeps its
|
|
33
|
+
unbounded on-demand ledger, untouched.
|
|
34
|
+
- **Per-option validation by name.** `maxNodes` / `maxLinks` / `maxFlushPasses` must
|
|
35
|
+
be finite integers `>= 1`; `prealloc` must be exactly `"eager"` | `"lazy"`;
|
|
36
|
+
`onCapacityExceeded` must be exactly `"throw"` | `"grow"`. Each bad value throws a
|
|
37
|
+
`TypeError` prefixed `createRegistry: "<option>"` at construction -- not a delayed
|
|
38
|
+
internal `nextFree` TypeError on first use.
|
|
39
|
+
- **Config-shape gate.** A non-object, `null`, or array `config` throws
|
|
40
|
+
`createRegistry: "config"` rather than dying later.
|
|
41
|
+
- **Unknown-key rejection with did-you-mean.** An unrecognized key throws with a
|
|
42
|
+
Levenshtein suggestion (`maxNods` -> `maxNodes`, `preAlloc` -> `prealloc`) instead
|
|
43
|
+
of being silently ignored.
|
|
44
|
+
- **`stats()` gains `nodePoolPopulation` / `linkPoolPopulation`** -- the TRUE count
|
|
45
|
+
of physically constructed nodes/links (`nodePool.length` / `linkPool.length`),
|
|
46
|
+
distinct from the `*Capacity` ledgers. A silently mis-set `prealloc` is now
|
|
47
|
+
observable (population 0 under lazy) instead of telemetry-blind. **This is the one
|
|
48
|
+
observable API change: `stats()` grows 11 -> 13 keys, purely additive** -- no
|
|
49
|
+
existing key changed; only an exact key-*count* assertion is affected (updated
|
|
50
|
+
in `test/03-pool.test.mjs`).
|
|
51
|
+
|
|
52
|
+
### Tests
|
|
53
|
+
|
|
54
|
+
`test/30-config-validation.test.mjs` adds the full 25-config matrix, the did-you-mean
|
|
55
|
+
cases, the eager ceiling, the population contract, and the three OOM rows as isolated
|
|
56
|
+
child-process cases (`test/30-config-oom.child.mjs`) proving the fixed engine throws
|
|
57
|
+
+ exits 0 under a 256 MB cap where the unvalidated engine died.
|
|
58
|
+
|
|
59
|
+
## [1.5.0-rc.2] -- 2026-08-18
|
|
60
|
+
|
|
61
|
+
Version-only bump over rc.1; engine byte-identical past the header. Superseded by
|
|
62
|
+
rc.3, the first entry to carry an engine change.
|
|
63
|
+
|
|
7
64
|
## [1.5.0-rc.1] -- 2026-07-27
|
|
8
65
|
|
|
9
66
|
Release candidate for 1.5.0. Promotes `1.5.0-beta.8` with **no engine change** --
|
|
10
|
-
`Signal.js`
|
|
11
|
-
byte-identical to
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### Changed -- the torture suite is now
|
|
17
|
-
|
|
18
|
-
The `bench/torture/` runner (`run.mjs`) now registers **
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
(
|
|
28
|
-
`
|
|
29
|
-
|
|
67
|
+
`Signal.js` and `Signal.d.ts` are FROZEN: byte-identical to beta.8, hot paths
|
|
68
|
+
byte-identical to 1.4.0. What this RC finalises is the *torture surface*: it is
|
|
69
|
+
brought to full **parity with 1.4.4** at **22 scenarios (19 semantic + 3 soak)**.
|
|
70
|
+
This work is **verification-only** -- the added test/bench material OBSERVES the
|
|
71
|
+
frozen engine and pins its ACTUAL behaviour; nothing in the engine moved.
|
|
72
|
+
|
|
73
|
+
### Changed -- the torture suite is now at full 1.4.4 parity (22 scenarios)
|
|
74
|
+
|
|
75
|
+
The `bench/torture/` runner (`run.mjs`) now registers **22** scenarios in two
|
|
76
|
+
groups -- **19 semantic + 3 soak** -- up from the sixteen (13 semantic + 3 soak)
|
|
77
|
+
the earlier RC listed. Six scenarios are finalised here, ported from 1.4.4 and
|
|
78
|
+
re-pointed / re-targeted to the surface 1.5.0 actually ships:
|
|
79
|
+
|
|
80
|
+
- `owner-torture` -- getOwner/runWithOwner capture-restore, live adoption +
|
|
81
|
+
cascade-dispose, ABA stale-handle -> rooted degradation, dep isolation. 1.5.0
|
|
82
|
+
has no `createScope`, so every owner scope is built from an **effect as the
|
|
83
|
+
unit of ownership** (getOwner() inside an effect body captures that effect;
|
|
84
|
+
its stop() cascade-disposes adopted children).
|
|
85
|
+
- `error-torture` -- throwing effect bodies: per-effect buffering, exact-order
|
|
86
|
+
`AggregateError`, single-throw re-thrown unwrapped, buffer drain flat over
|
|
87
|
+
4096 throw/clean cycles. Confirmed byte-identical to 1.4.4 (Signal.js :816 /
|
|
88
|
+
:823-825 / :829-839).
|
|
89
|
+
- `deep-chain-torture` -- `pullComputed` recursion fails closed with a
|
|
90
|
+
**RangeError** at depth; the iterative push path stays open at equal depth.
|
|
91
|
+
- `zerogc-torture` -- the zero-GC hot path made falsifiable via
|
|
92
|
+
`@zakkster/lite-gc-profiler` (a **dev-only** dependency; `dependencies` stays
|
|
93
|
+
empty). `ZEROGC_BREAK=1` self-test confirmed to reject a planted allocation.
|
|
94
|
+
- `introspect-torture` -- describe/forEach*/hasObservers/ownerOf + the ABA
|
|
95
|
+
gen-stamp guard. Section 7 (ownerOf/forEachOwned) re-targeted off `createScope`
|
|
96
|
+
onto an effect-body owner.
|
|
97
|
+
- `lifecycle-torture` -- createRoot detachment + destroy registry reset; the
|
|
98
|
+
root-vs-owner scenario nests `createRoot` inside an effect body so detachment
|
|
99
|
+
is observable. `destroy()` leaves `stats().activeNodes === 0`.
|
|
100
|
+
|
|
101
|
+
**First-time execution on the 1.5.0 engine.** Several lanes that only ever
|
|
102
|
+
SKIPPED on earlier cuts now EXECUTE here for the first time: `box-torture`
|
|
103
|
+
(signalBox/computedBox), the **`churn-box`** lane inside `zerogc-torture`
|
|
104
|
+
(signalBox create+dispose churn -- retains 0 B/call, `poolGrowths` delta 0,
|
|
105
|
+
`activeNodes` back to baseline), and the owner/root lifecycle scenarios
|
|
106
|
+
(`lifecycle-torture` + `owner-torture` via getOwner/runWithOwner/createRoot).
|
|
30
107
|
|
|
31
108
|
Every scenario feature-detects and **skips cleanly** below the version that
|
|
32
|
-
introduces its feature
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
`
|
|
36
|
-
`
|
|
37
|
-
|
|
109
|
+
introduces its feature. On the 1.5.0 engine the runner executes **15 semantic
|
|
110
|
+
scenarios** and reports a clean SKIP for the four feature-gated later-version
|
|
111
|
+
ones: `scope-torture` (1.6.0 `createScope`), `flush-torture` (1.7.0
|
|
112
|
+
`flushStrategy`), `cleanup-return-torture` (1.8.0 effect-return cleanup), and
|
|
113
|
+
`dispose-torture` (1.9.0 `Symbol.dispose`). Each of the three soaks now carries
|
|
114
|
+
an `Int32Array` value-correctness oracle (allocated once, a rotating sampled
|
|
115
|
+
window per tick with zero per-tick allocation, a full sweep at teardown).
|
|
38
116
|
|
|
39
|
-
**Final verification for this RC (
|
|
117
|
+
**Final verification for this RC (`--expose-gc`):**
|
|
40
118
|
|
|
41
119
|
| group | result |
|
|
42
120
|
| ----- | ------ |
|
|
43
|
-
| `torture:semantic` |
|
|
44
|
-
| `torture:soak` | 3/3 pass -- zero errors, every pool back to its leaf-only floor
|
|
121
|
+
| `torture:semantic` | 19/19 pass -- 15 executed, 4 clean skips (scope/flush/cleanup-return/dispose) |
|
|
122
|
+
| `torture:soak` | 3/3 pass -- zero errors, every pool back to its leaf-only floor, oracle sweeps 0 mismatches |
|
|
45
123
|
|
|
46
124
|
The mutation-evidence table in `bench/torture/README.md` is unchanged and still
|
|
47
125
|
holds: the soaks catch 1 of 5 injected engine defects, the semantic files catch
|
|
@@ -50,24 +128,33 @@ scenario.
|
|
|
50
128
|
|
|
51
129
|
### Changed -- README and llms.txt torture sections corrected
|
|
52
130
|
|
|
53
|
-
Both root docs
|
|
54
|
-
|
|
55
|
-
the
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
131
|
+
Both root docs now describe the **22-scenario suite (19 semantic + 3 soak)**, the
|
|
132
|
+
15-run / 4-skip split on the 1.5.0 engine, the six scenarios finalised in this RC,
|
|
133
|
+
and the feature gates -- matching `bench/torture/run.mjs`. The unit test count is
|
|
134
|
+
updated for the new `test/29-throwing-equals` (7 tests).
|
|
135
|
+
|
|
136
|
+
### Added -- test/29-throwing-equals
|
|
137
|
+
|
|
138
|
+
A new `test/29-throwing-equals.test.mjs` (7 `it()` across three call sites)
|
|
139
|
+
pins the behaviour of a user `equals` predicate that THROWS at each of the three
|
|
140
|
+
LOGICAL sites the engine invokes it on the callable surface: signal-set pre-check
|
|
141
|
+
(Signal.js :1096), batch-revert check (:1103), and computed re-eval (:977). A
|
|
142
|
+
raw grep shows five physical `eq()` calls because 1.5.0's `signalBox` mirrors the
|
|
143
|
+
callable set path with its own pre-check/revert pair (:1201 / :1208); they
|
|
144
|
+
collapse to the same three logical sites and are byte-identical in logic. No
|
|
145
|
+
behavioral divergence from 1.4.4 was observed -- every assertion holds identically.
|
|
60
146
|
|
|
61
147
|
### Notes -- unit suite and the devtools real-boot rig
|
|
62
148
|
|
|
63
|
-
The unit suite is **
|
|
64
|
-
`17-reactivity`) in the full workspace, i.e. with the sibling
|
|
65
|
-
`@zakkster/lite-devtools` resolvable
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
149
|
+
The unit suite is **461 tests: 460 pass + 1 skip, 0 fail** (the architectural SSR
|
|
150
|
+
N/A in `17-reactivity`) in the full workspace, i.e. with the sibling
|
|
151
|
+
`@zakkster/lite-devtools` resolvable, and now includes the 7-test
|
|
152
|
+
`test/29-throwing-equals`. `test/25-devtools-real-boot.test.mjs` is a 10-test
|
|
153
|
+
real-rig that boots the installed Devtools against the local engine; a bare
|
|
154
|
+
checkout without that sibling cannot resolve the specifier and reports 10 fewer.
|
|
155
|
+
No engine test regressed; the gap is purely the sibling package's presence.
|
|
156
|
+
`@zakkster/lite-gc-profiler` is added to `devDependencies` for `zerogc-torture`;
|
|
157
|
+
it is dev-only and `dependencies` stays empty (zero runtime deps).
|
|
71
158
|
|
|
72
159
|
Nothing new ships in the tarball: `files[]` still excludes `bench/`, so this RC's
|
|
73
160
|
publishable surface (`Signal.js`, `Signal.d.ts`, `Watch.js`, docs) is identical
|
package/README.md
CHANGED
|
@@ -792,6 +792,7 @@ Four tiers, all reproducible.
|
|
|
792
792
|
- **`28-run-with-owner.test.mjs`** -- `getOwner` / `runWithOwner` (1.5.0-beta.2), the re-attach companion. 16 tests, structured in three groups: basic shape (7 tests: undefined outside, effect/computed inside, restore-on-return, throw-safety, nesting), degradation (3 tests: null / undefined / signal-handle all fall through to rooted execution), and the three **hazard pins** that a raw-pointer implementation fails: (i) recycled-slot cascade -- capture, dispose owner, allocate an effect that reuses the pool slot, `runWithOwner(captured)` must not adopt into the recycled slot's new resident; (ii) corpse adoption -- capture, dispose owner but not-yet-recycled, `runWithOwner(captured, () => effect(...))` must not crash with `RangeError` in the cleanup recursion; (iii) composed -- both together, continuation must survive stranger re-runs AND disposal. All three fail against the naive `getOwner() { return currentOwner; }` shape (empirically verified against a 1.5.0-beta engine patched with the raw-pointer alternative -- `harness/owner-hazard-repro.mjs`); all three pass with the `describeNode` gen-stamped handle + `liveNode` ABA guard that ships.
|
|
793
793
|
- **`25-devtools-real-boot.test.mjs`** -- Devtools/Studio contract (10 tests). Boots the actual `Devtools.js` against the 1.5.0 engine and exercises all 19 Devtools exports plus the 10 symbols Studio imports from Devtools. Pins the ghost contract: heavy introspection (graph walk, owner-tree, observer descriptors) adds **zero** nodes to the live graph. Catches the real-rig failure mode where importing the package by its own name from a repo whose `package.json` declares `name: "@zakkster/lite-signal"` resolves to the published build instead of the local engine.
|
|
794
794
|
- **`26-free-list-invariant.test.mjs`** -- the 1.2.2 audit's cleanliness pins (3 invariant tests + 1 targeted coverage test). Asserts directly -- by inspecting freshly-allocated nodes through the documented `describe()` -> `NODE_PTR` introspection protocol -- that the `ReactiveNode` constructor and the fresh-pool-growth path initialize the ten fields the audit removed from `createNode` to identical values, so the deleted writes were defending against a state the engine cannot produce on a clean free list. The 4th test covers the swallow-on-self-dispose-then-throw branch in `pullComputed` (the path that lifted branch coverage from 98.07% to 98.43%).
|
|
795
|
+
- **`29-throwing-equals.test.mjs`** -- a user `equals` predicate that THROWS (7 tests across three call sites). Pins the fail-predictably behaviour at each of the three LOGICAL sites the engine invokes `equals` on the callable surface: signal-set pre-check (propagates the original error, leaves the signal unmutated, fires no downstream), batch-revert check (PINNED: the throw lands after the value write, strands the version bump so downstream fires, and the registry recovers on the next batch), and computed re-eval (caches the throw as `FLAG_HAS_ERROR`, re-throws the same error until a dep change re-evaluates cleanly). 1.5.0's `signalBox` mirrors the callable set path with its own pre-check/revert pair, so a raw grep shows five physical `eq()` calls collapsing to the same three logical sites -- byte-identical in logic, no divergence from 1.4.4.
|
|
795
796
|
|
|
796
797
|
```bash
|
|
797
798
|
npm test
|
|
@@ -822,18 +823,23 @@ npm run bench
|
|
|
822
823
|
|
|
823
824
|
### Tier 4 -- Torture (correctness and resources under chaos)
|
|
824
825
|
|
|
825
|
-
`bench/torture/` holds the complete **
|
|
826
|
-
soak)** in two groups, behind one runner --
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
perf harness.
|
|
826
|
+
`bench/torture/` holds the complete **22-scenario suite (19 semantic + 3
|
|
827
|
+
soak)** in two groups, behind one runner -- full parity with 1.4.4. They are not
|
|
828
|
+
perf benchmarks: the ops/sec figures reflect random workload composition, not
|
|
829
|
+
engine throughput -- `bench/benchmark.mjs` remains the canonical perf harness.
|
|
830
830
|
|
|
831
831
|
Every scenario feature-detects and **skips cleanly** below the engine version
|
|
832
832
|
that introduces its feature, so the whole set is safe to ship on the 1.5.0 engine
|
|
833
|
-
and stays green from 1.4.x forward. On this engine the runner executes **
|
|
834
|
-
semantic scenarios**
|
|
835
|
-
|
|
836
|
-
`
|
|
833
|
+
and stays green from 1.4.x forward. On this engine the runner executes **15
|
|
834
|
+
semantic scenarios** -- including `owner-torture`, `error-torture`,
|
|
835
|
+
`deep-chain-torture`, `zerogc-torture` (its `churn-box` signalBox lane),
|
|
836
|
+
`introspect-torture` and `lifecycle-torture`, which EXECUTE here for the first
|
|
837
|
+
time via signalBox and the getOwner/runWithOwner/createRoot surface -- and
|
|
838
|
+
reports a clean SKIP for the four later-version ones (`scope-torture` 1.6.0,
|
|
839
|
+
`flush-torture` 1.7.0, `cleanup-return-torture` 1.8.0, `dispose-torture` 1.9.0).
|
|
840
|
+
Each soak carries an `Int32Array` value-correctness oracle: one allocation up
|
|
841
|
+
front, a rotating sampled window per tick (zero per-tick allocation), a full
|
|
842
|
+
sweep at teardown. Verified green: **22/22 passed**.
|
|
837
843
|
|
|
838
844
|
```bash
|
|
839
845
|
npm run torture # everything
|
package/Signal.d.ts
CHANGED
|
@@ -122,6 +122,16 @@ export interface RegistryStats {
|
|
|
122
122
|
/** Node-pool capacity ledger. Doubles under the `"grow"` policy; under `"lazy"`
|
|
123
123
|
* prealloc it may exceed the count of physically constructed nodes. */
|
|
124
124
|
nodePoolCapacity: number;
|
|
125
|
+
/** TRUE node-pool population: the number of `ReactiveNode`s physically constructed
|
|
126
|
+
* (`nodePool.length`), distinct from the `nodePoolCapacity` ledger. Under
|
|
127
|
+
* `prealloc:"lazy"` (or a silently-flipped `prealloc` typo) this stays 0 until
|
|
128
|
+
* first demand while capacity reads the ledger -- so a mis-set `prealloc` is
|
|
129
|
+
* observable here rather than telemetry-blind. Added in the 1.4.5 backport. */
|
|
130
|
+
nodePoolPopulation: number;
|
|
131
|
+
/** TRUE link-pool population: the number of `ReactiveLink`s physically constructed
|
|
132
|
+
* (`linkPool.length`), distinct from the `linkPoolCapacity` ledger. Added in the
|
|
133
|
+
* 1.4.5 backport. */
|
|
134
|
+
linkPoolPopulation: number;
|
|
125
135
|
/** Number of nodes currently allocated (signals + computeds + alive effects). */
|
|
126
136
|
activeNodes: number;
|
|
127
137
|
/**
|
package/Signal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @zakkster/lite-signal v1.5.0
|
|
2
|
+
* @zakkster/lite-signal v1.5.0
|
|
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:
|
|
@@ -209,10 +209,134 @@ export class CapacityError extends Error {
|
|
|
209
209
|
* Error prefixed `"CycleError:"`.
|
|
210
210
|
* @returns {Registry}
|
|
211
211
|
*/
|
|
212
|
+
/** The only config keys {@link createRegistry} recognizes. Anything else is
|
|
213
|
+
* rejected at construction with a did-you-mean hint (fail closed on an
|
|
214
|
+
* unverified state -- an unknown key is an error, never a silent ignore). */
|
|
215
|
+
const ALLOWED_KEYS = ["maxNodes", "maxLinks", "prealloc", "onCapacityExceeded", "maxFlushPasses"];
|
|
216
|
+
|
|
217
|
+
/** Ceiling on eager pool construction: `(maxNodes + maxLinks)` objects. A finite
|
|
218
|
+
* but absurd `maxNodes` (e.g. `1e9`, a plausible typo for `1e5`) that would
|
|
219
|
+
* otherwise OOM the process is refused BY NAME at construction rather than
|
|
220
|
+
* allocating forever. Only the `"eager"` path is bounded; `"lazy"` keeps its
|
|
221
|
+
* unbounded ledger. `1 << 24` == 16777216. */
|
|
222
|
+
const EAGER_CONSTRUCT_CEILING = 1 << 24;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Levenshtein edit distance between two short strings. Cold: called only on the
|
|
226
|
+
* constructor error path, over the known option names, so its per-call array
|
|
227
|
+
* allocation never touches any hot path.
|
|
228
|
+
* @param {string} a
|
|
229
|
+
* @param {string} b
|
|
230
|
+
* @returns {number}
|
|
231
|
+
*/
|
|
232
|
+
function editDistance(a, b) {
|
|
233
|
+
const m = a.length;
|
|
234
|
+
const n = b.length;
|
|
235
|
+
const prev = new Array(n + 1);
|
|
236
|
+
const cur = new Array(n + 1);
|
|
237
|
+
for (let j = 0; j <= n; j++) prev[j] = j;
|
|
238
|
+
for (let i = 1; i <= m; i++) {
|
|
239
|
+
cur[0] = i;
|
|
240
|
+
for (let j = 1; j <= n; j++) {
|
|
241
|
+
const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
|
|
242
|
+
let min = prev[j] + 1;
|
|
243
|
+
if (cur[j - 1] + 1 < min) min = cur[j - 1] + 1;
|
|
244
|
+
if (prev[j - 1] + cost < min) min = prev[j - 1] + cost;
|
|
245
|
+
cur[j] = min;
|
|
246
|
+
}
|
|
247
|
+
for (let j = 0; j <= n; j++) prev[j] = cur[j];
|
|
248
|
+
}
|
|
249
|
+
return prev[n];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The closest known config key to `key` within edit distance 2 (case-folded so
|
|
254
|
+
* `preAlloc`/`MAXNODES` resolve), or null when nothing is close. Cold path only.
|
|
255
|
+
* @param {string} key
|
|
256
|
+
* @returns {string|null}
|
|
257
|
+
*/
|
|
258
|
+
function suggestKey(key) {
|
|
259
|
+
const lk = key.toLowerCase();
|
|
260
|
+
let best = null;
|
|
261
|
+
let bestD = 3;
|
|
262
|
+
for (let i = 0; i < ALLOWED_KEYS.length; i++) {
|
|
263
|
+
const d = editDistance(lk, ALLOWED_KEYS[i].toLowerCase());
|
|
264
|
+
if (d < bestD) { bestD = d; best = ALLOWED_KEYS[i]; }
|
|
265
|
+
}
|
|
266
|
+
return bestD <= 2 ? best : null;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Render a rejected value for an error message, e.g. `42 (number)`.
|
|
271
|
+
* Cold: this runs only on a throw path, never on any hot path. `String(symbol)`
|
|
272
|
+
* throws, so symbols are stringified defensively.
|
|
273
|
+
* @param {*} v
|
|
274
|
+
* @returns {string}
|
|
275
|
+
*/
|
|
276
|
+
function received(v) {
|
|
277
|
+
return (typeof v === "symbol" ? v.toString() : String(v)) + " (" + typeof v + ")";
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Validate that a numeric option is a finite integer >= 1. Cold: constructor
|
|
282
|
+
* error path only. Throws a {@link TypeError} prefixed `createRegistry: "<name>"`.
|
|
283
|
+
* @param {*} v
|
|
284
|
+
* @param {string} name
|
|
285
|
+
*/
|
|
286
|
+
function requirePositiveInt(v, name) {
|
|
287
|
+
if (!Number.isInteger(v) || v < 1) {
|
|
288
|
+
throw new TypeError(
|
|
289
|
+
'createRegistry: "' + name + '" must be a finite integer >= 1, received ' + received(v) + '.'
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
212
294
|
export function createRegistry(config) {
|
|
213
295
|
const NODE_PTR = Symbol("node_ptr");
|
|
214
296
|
const NODE_GEN = Symbol("node_gen");
|
|
215
297
|
|
|
298
|
+
// --- 1.4.5 backport: createRegistry input validation (all cold, constructor-only).
|
|
299
|
+
// Config-shape gate: accept `undefined` or a non-null, non-array object; reject
|
|
300
|
+
// `null`, primitives and arrays BY NAME rather than dying later on `config.maxNodes`
|
|
301
|
+
// or an internal `nextFree` read (fail closed on an unverified state).
|
|
302
|
+
if (config !== undefined && (config === null || typeof config !== "object" || Array.isArray(config))) {
|
|
303
|
+
throw new TypeError(
|
|
304
|
+
'createRegistry: "config" must be a plain object or undefined, received ' + received(config) + '.'
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
if (config !== undefined) {
|
|
308
|
+
// Per-option validation BY NAME -- a bad value throws `createRegistry: "<option>"`
|
|
309
|
+
// at construction, not a delayed internal TypeError on first use.
|
|
310
|
+
if (config.maxNodes !== undefined) requirePositiveInt(config.maxNodes, "maxNodes");
|
|
311
|
+
if (config.maxLinks !== undefined) requirePositiveInt(config.maxLinks, "maxLinks");
|
|
312
|
+
if (config.maxFlushPasses !== undefined) requirePositiveInt(config.maxFlushPasses, "maxFlushPasses");
|
|
313
|
+
if (config.prealloc !== undefined && config.prealloc !== "eager" && config.prealloc !== "lazy") {
|
|
314
|
+
throw new TypeError(
|
|
315
|
+
'createRegistry: "prealloc" must be "eager" or "lazy", received ' + received(config.prealloc) + '.'
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
if (config.onCapacityExceeded !== undefined && config.onCapacityExceeded !== "throw" && config.onCapacityExceeded !== "grow") {
|
|
319
|
+
throw new TypeError(
|
|
320
|
+
'createRegistry: "onCapacityExceeded" must be "throw" or "grow", received ' + received(config.onCapacityExceeded) + '.'
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
// Unknown-key rejection with a did-you-mean hint (`preAlloc` -> `prealloc`,
|
|
324
|
+
// `maxNods` -> `maxNodes`). Own enumerable keys only; cold path.
|
|
325
|
+
const badKeys = Object.keys(config);
|
|
326
|
+
for (let bi = 0; bi < badKeys.length; bi++) {
|
|
327
|
+
const bk = badKeys[bi];
|
|
328
|
+
if (ALLOWED_KEYS.indexOf(bk) === -1) {
|
|
329
|
+
const hint = suggestKey(bk);
|
|
330
|
+
throw new TypeError(
|
|
331
|
+
'createRegistry: "' + bk + '" is not a recognized option' +
|
|
332
|
+
(hint !== null ? ' (did you mean "' + hint + '"?)' : '') +
|
|
333
|
+
'. Allowed: ' + ALLOWED_KEYS.join(", ") + '.'
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// --- end 1.4.5 backport.
|
|
339
|
+
|
|
216
340
|
let currentNodesCapacity = (config !== undefined && config.maxNodes !== undefined) ? config.maxNodes : 1024;
|
|
217
341
|
let currentLinkCapacity = (config !== undefined && config.maxLinks !== undefined) ? config.maxLinks : currentNodesCapacity * 4;
|
|
218
342
|
const policy = (config !== undefined && config.onCapacityExceeded !== undefined) ? config.onCapacityExceeded : "throw";
|
|
@@ -225,6 +349,20 @@ export function createRegistry(config) {
|
|
|
225
349
|
// steady state is identical after warm-up, but the heap no longer carries
|
|
226
350
|
// never-used live objects for every major GC to mark.
|
|
227
351
|
const prealloc = (config !== undefined && config.prealloc !== undefined) ? config.prealloc : "eager";
|
|
352
|
+
// Eager-construction ceiling (cold): `"eager"` builds `(maxNodes + maxLinks)`
|
|
353
|
+
// objects up front; a finite-but-absurd capacity (e.g. `1e9`) would OOM the
|
|
354
|
+
// process with an uncatchable SIGABRT, not a throw. Refuse BY NAME before
|
|
355
|
+
// allocating. Named for the larger driver. `"lazy"` keeps its unbounded ledger.
|
|
356
|
+
if (prealloc === "eager" && (currentNodesCapacity + currentLinkCapacity) > EAGER_CONSTRUCT_CEILING) {
|
|
357
|
+
const driver = currentLinkCapacity > currentNodesCapacity ? "maxLinks" : "maxNodes";
|
|
358
|
+
throw new TypeError(
|
|
359
|
+
'createRegistry: "' + driver + '" eager construction of ' +
|
|
360
|
+
(currentNodesCapacity + currentLinkCapacity) + ' objects (maxNodes ' +
|
|
361
|
+
currentNodesCapacity + ' + maxLinks ' + currentLinkCapacity + ') exceeds the ceiling of ' +
|
|
362
|
+
EAGER_CONSTRUCT_CEILING + '. Use prealloc:"lazy" for an unbounded on-demand ledger, ' +
|
|
363
|
+
'or lower the capacity.'
|
|
364
|
+
);
|
|
365
|
+
}
|
|
228
366
|
const nodePool = [];
|
|
229
367
|
let freeNodeHead = null;
|
|
230
368
|
const linkPool = [];
|
|
@@ -1562,6 +1700,12 @@ export function createRegistry(config) {
|
|
|
1562
1700
|
pooledLinks: currentLinkCapacity - activeLinks,
|
|
1563
1701
|
linkPoolCapacity: currentLinkCapacity,
|
|
1564
1702
|
nodePoolCapacity: currentNodesCapacity,
|
|
1703
|
+
// 1.4.5 backport: TRUE pool population (nodePool.length / linkPool.length),
|
|
1704
|
+
// distinct from the *Capacity ledgers above. Under prealloc:"lazy" (or a
|
|
1705
|
+
// silently-flipped `prealloc` typo) population stays 0 while capacity reads
|
|
1706
|
+
// the ledger -- so a mis-set prealloc is now observable, not telemetry-blind.
|
|
1707
|
+
nodePoolPopulation: nodePool.length,
|
|
1708
|
+
linkPoolPopulation: linkPool.length,
|
|
1565
1709
|
activeNodes,
|
|
1566
1710
|
// 1.4: cumulative lifecycle counters (monotonic; reset by destroy()).
|
|
1567
1711
|
// Derive: allocationRate = deltatotalAllocations/deltat; poolReuseRate =
|
package/llms.txt
CHANGED
|
@@ -25,7 +25,7 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
|
|
|
25
25
|
- **isTracking**: `isTracking()` returns true iff a read right now would record a dependency on this registry (for wrappers that lazily allocate signals).
|
|
26
26
|
- **onCleanup**: registers teardown for the current computation; fires before each re-run and once on dispose. Works in effects and computeds.
|
|
27
27
|
- **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.
|
|
28
|
-
- **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.
|
|
28
|
+
- **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 at construction (1.5.0, backported from 1.4.5):** every option is checked BY NAME (`maxNodes`/`maxLinks`/`maxFlushPasses` finite integer `>= 1`; `prealloc` exactly `"eager"`|`"lazy"`; `onCapacityExceeded` exactly `"throw"`|`"grow"`), a bad shape or unknown key throws a `TypeError` prefixed `createRegistry: "<name>"` with a did-you-mean hint, and an absurd eager capacity (`maxNodes:Infinity`/`1e9`) is refused before it can OOM the process. `stats()` gains `nodePoolPopulation` / `linkPoolPopulation` (true constructed-object counts, distinct from the `*Capacity` ledgers) -> **13 keys**.
|
|
29
29
|
- **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.
|
|
30
30
|
|
|
31
31
|
## Architecture invariants
|
|
@@ -53,30 +53,55 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
|
|
|
53
53
|
|
|
54
54
|
## Version notes
|
|
55
55
|
|
|
56
|
-
- **1.5.0
|
|
57
|
-
`Signal.js`
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
56
|
+
- **1.5.0** (current): stable. Graduates rc.3 with **no further engine change** --
|
|
57
|
+
`Signal.js`/`Signal.d.ts` byte-identical to rc.3 past the header, `bench/torture/run.mjs`
|
|
58
|
+
unchanged at 22/22. First stable to carry the **1.4.5 `createRegistry` input
|
|
59
|
+
validation** (folded in at rc.3) atop the 1.5.0 surface (`signalBox`/`computedBox`,
|
|
60
|
+
`createRoot`, `getOwner`/`runWithOwner`). Drop-in over 1.4.5; the one observable delta
|
|
61
|
+
on existing code is `stats()` growing 11 -> 13 keys (additive). See CHANGELOG `[1.5.0]`.
|
|
62
|
+
- **1.5.0-rc.3**: backports the **1.4.5 `createRegistry` input validation**
|
|
63
|
+
(all four findings) onto the rc.2 engine. First engine change since the RC line
|
|
64
|
+
began -- but only `createRegistry`'s *cold* construction path moved; hot paths stay
|
|
65
|
+
byte-identical to 1.4.0 and `bench/torture/run.mjs` is unchanged at 22/22. Bad
|
|
66
|
+
config now throws a named `TypeError` (unknown keys get a did-you-mean); an absurd
|
|
67
|
+
eager capacity is refused before it can OOM the process; `stats()` grows 11 -> 13
|
|
68
|
+
keys (adds `nodePoolPopulation`/`linkPoolPopulation`, purely additive). New suite
|
|
69
|
+
`test/30-config-validation.test.mjs` (matrix + ceiling + population + OOM child
|
|
70
|
+
processes). See CHANGELOG `[1.5.0-rc.3]`.
|
|
71
|
+
- **1.5.0-rc.2**: version-only bump over rc.1; engine byte-identical past the header.
|
|
72
|
+
Superseded by rc.3.
|
|
73
|
+
- **1.5.0-rc.1**: release candidate for 1.5.0. **No engine change** --
|
|
74
|
+
`Signal.js` and `Signal.d.ts` are FROZEN: byte-identical to beta.8, hot paths
|
|
75
|
+
byte-identical to 1.4.0. This RC brings the torture surface to full **parity
|
|
76
|
+
with 1.4.4**: `bench/torture/run.mjs` now registers the complete **22-scenario
|
|
77
|
+
suite (19 semantic + 3 soak)**, up from the sixteen (13 semantic + 3 soak) the
|
|
78
|
+
earlier RC listed. Six scenarios are finalised here -- `owner-torture`
|
|
79
|
+
(getOwner/runWithOwner capture-restore + ABA degradation), `error-torture`
|
|
80
|
+
(throwing effect bodies: per-effect buffering, exact-order AggregateError,
|
|
81
|
+
buffer drain over 4096 cycles), `deep-chain-torture` (pullComputed recursion
|
|
82
|
+
fail-closed with a RangeError vs the iterative push path), `zerogc-torture`
|
|
83
|
+
(the zero-GC hot path made falsifiable via `@zakkster/lite-gc-profiler` --
|
|
84
|
+
a **dev-only** dependency), `introspect-torture` (describe/forEach*/ownerOf +
|
|
85
|
+
the ABA gen-stamp guard), and `lifecycle-torture` (createRoot detachment +
|
|
86
|
+
destroy registry reset). This is **verification-only**: the new files OBSERVE
|
|
87
|
+
the frozen engine and pin its actual behaviour; nothing in the engine moved.
|
|
88
|
+
A notable milestone -- several lanes that only ever SKIPPED on earlier cuts
|
|
89
|
+
EXECUTE on the 1.5.0 engine for the FIRST TIME: `box-torture`
|
|
90
|
+
(signalBox/computedBox), the `churn-box` lane inside `zerogc-torture`
|
|
91
|
+
(signalBox create+dispose churn retains 0 B/call), and the owner/root
|
|
92
|
+
lifecycle scenarios `lifecycle-torture` + `owner-torture` (via
|
|
93
|
+
getOwner/runWithOwner/createRoot). On the 1.5.0 engine the runner executes
|
|
94
|
+
**15 semantic** scenarios and reports a clean SKIP for the four feature-gated
|
|
95
|
+
later-version ones (`scope-torture` 1.6.0, `flush-torture` 1.7.0,
|
|
96
|
+
`cleanup-return-torture` 1.8.0, `dispose-torture` 1.9.0) -- verified green:
|
|
97
|
+
**22/22 passed** (19 semantic + 3 soak, zero errors, pools back to their
|
|
98
|
+
leaf-only floor; each soak now carries an Int32Array value-oracle sweep with
|
|
99
|
+
zero mismatches). Unit suite is **461 tests: 460 pass + 1 skip** (SSR N/A in
|
|
100
|
+
`17-reactivity`) with the sibling `@zakkster/lite-devtools` present, including
|
|
101
|
+
the new 7-test `test/29-throwing-equals` that pins the three `equals()` call
|
|
102
|
+
sites. Nothing new ships: `files[]` excludes `bench/` and `dependencies` stays
|
|
103
|
+
empty (zero runtime deps), so the publishable surface is byte-identical to
|
|
104
|
+
beta.8 apart from version strings. Drop-in over 1.5.0-beta.8.
|
|
80
105
|
|
|
81
106
|
- **1.5.0-beta.8**: the **torture-surface bump**. No engine change --
|
|
82
107
|
the only edit to `Signal.js` is the version string in its banner. The torture
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakkster/lite-signal",
|
|
3
|
-
"version": "1.5.0
|
|
3
|
+
"version": "1.5.0",
|
|
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",
|
|
@@ -85,6 +85,7 @@
|
|
|
85
85
|
"sideEffects": false,
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@zakkster/lite-devtools": "^1.2.0",
|
|
88
|
+
"@zakkster/lite-gc-profiler": "^1.15.0",
|
|
88
89
|
"@zakkster/lite-profiler": "^1.1.0",
|
|
89
90
|
"@zakkster/lite-profiler-signal": "^1.2.0",
|
|
90
91
|
"@zakkster/lite-signal": "^1.3.0 || >=1.4.0-beta.0 || >=1.6.0-preview.0",
|