@zakkster/lite-signal 1.7.0-preview.1 → 1.8.0-alpha.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 +236 -3
- package/README.md +114 -4
- package/Signal.d.ts +16 -2
- package/Signal.js +62 -5
- package/llms.txt +17 -1
- package/package.json +29 -5
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,239 @@ 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.8.0-preview] -- 2026-07-XX
|
|
8
|
+
|
|
9
|
+
The **effect cleanup return** minor -- Reflex-study pattern A. One additive
|
|
10
|
+
hot-path change: an effect body may now `return` a cleanup function, which
|
|
11
|
+
runs before the next re-run and on dispose, composing with imperative
|
|
12
|
+
`onCleanup(fn)` in call order. Plus the recurring **`getOwner` /
|
|
13
|
+
`runWithOwner` forward-port from 1.5.0-beta.2** -- the 1.8.0-preview
|
|
14
|
+
`Signal.js` was branched from the same pre-1.5.0-beta.2 base as 1.7.0-preview
|
|
15
|
+
and 1.6.0-alpha, so the two async-gap ownership primitives are re-added
|
|
16
|
+
unchanged on this line.
|
|
17
|
+
|
|
18
|
+
The 1.7.0 flushStrategy scaffolding (`"eager"` | `"sab"` | `"manual"` + explicit
|
|
19
|
+
`r.flush()`) carries forward unchanged, as does every 1.5-era API surface
|
|
20
|
+
(`signalBox` / `computedBox` / `createRoot` / `createScope`) and every
|
|
21
|
+
propagation-core primitive. **Only `executeEffect` legitimately changed** from
|
|
22
|
+
1.7.0-preview; sha256 over the 15 other function bodies is byte-identical
|
|
23
|
+
between pristine 1.7.0-preview and pristine 1.8.0 (verified: `pullComputed`,
|
|
24
|
+
`markDownstream`, `flushEffects`, `allocateLink`, `severTail`, `createNode`,
|
|
25
|
+
`runCleanup`, `disposeNode`, `createRoot`, `createScope`, `flush`, `batch`,
|
|
26
|
+
`signal`, `computed`, `effect`).
|
|
27
|
+
|
|
28
|
+
Drop-in over 1.7.0-preview. The default is unchanged; effects that do not
|
|
29
|
+
return a function are unaffected (one `typeof` check per effect run, off the
|
|
30
|
+
mark/pull path).
|
|
31
|
+
|
|
32
|
+
### Added -- effect cleanup return (Reflex pattern A)
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
effect(() => {
|
|
36
|
+
const timer = setInterval(tick, 16);
|
|
37
|
+
return () => clearInterval(timer); // <-- ran before next re-run, and on dispose
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Solid/Vue/Reflex-compatible: an effect body may **return a cleanup function**.
|
|
42
|
+
It runs before the next re-run and on the effect's disposal, appended to any
|
|
43
|
+
imperative `onCleanup(fn)` registered inside the same body with the same append
|
|
44
|
+
semantics (single fn -> pair array -> push), so the two registration styles
|
|
45
|
+
**compose in call order**. Non-function returns are ignored. A self-disposed
|
|
46
|
+
body (one that generation-advances mid-execution) registers nothing -- the
|
|
47
|
+
slot may already host a new resident by the time the return is inspected, so
|
|
48
|
+
the guard is `node.gen === savedGen` before touching `node.cleanupFn`.
|
|
49
|
+
|
|
50
|
+
**Computeds are untouched.** A computed returning a function keeps treating
|
|
51
|
+
that function as the *value*. The cleanup-return check is inside
|
|
52
|
+
`executeEffect` and gated on the effect body's return type; the computed pull
|
|
53
|
+
path has no analogous inspection.
|
|
54
|
+
|
|
55
|
+
**Cost.** One `typeof` per effect run, entirely off the mark/pull path.
|
|
56
|
+
`executeEffect`'s sha256 is the only 1.7 -> 1.8 body change; every other
|
|
57
|
+
propagation function is byte-identical (see Hot-path safety below).
|
|
58
|
+
|
|
59
|
+
### Added -- `getOwner` / `runWithOwner` (carried forward from 1.5.0-beta.2)
|
|
60
|
+
|
|
61
|
+
The capture-and-restore companion to `createRoot`. `getOwner()` returns the
|
|
62
|
+
current lifecycle owner as an opaque, gen-stamped handle (`undefined` outside
|
|
63
|
+
any effect/computed body); `runWithOwner(handle, fn)` runs `fn` with that
|
|
64
|
+
owner reinstated so effects/computeds created directly in `fn` are adopted by
|
|
65
|
+
it (and cascade-dispose when the owner re-runs). Nulls the tracking observer
|
|
66
|
+
for `fn`'s direct body -- same pairing as `createRoot`, so accidental
|
|
67
|
+
cross-async dependency edges cannot form.
|
|
68
|
+
|
|
69
|
+
**Handles are gen-stamped.** They use the `describeNode` + `liveNode`
|
|
70
|
+
ABA-guard machinery (`NODE_GEN` stamp checked against the pool slot's current
|
|
71
|
+
gen), same as `describe` / `nodeId` / `forEachOwned` / `ownerOf` since 1.2.1.
|
|
72
|
+
Safe to hold across async boundaries: stale handles (owner disposed, slot
|
|
73
|
+
recycled by an unrelated effect via the LIFO free list) degrade to **rooted
|
|
74
|
+
execution** rather than adopting the continuation into the recycled slot's new
|
|
75
|
+
resident. Two hazards on the raw-pointer alternative are empirically
|
|
76
|
+
reproduced by `harness/owner-hazard-repro.mjs`:
|
|
77
|
+
|
|
78
|
+
- **Recycled-slot cascade death** -- capture, dispose owner, allocate a
|
|
79
|
+
stranger effect that reuses the slot; a raw-pointer
|
|
80
|
+
`runWithOwner(captured)` silently adopts the continuation into the
|
|
81
|
+
stranger; the stranger's next re-run cascade-disposes it.
|
|
82
|
+
- **Corpse adoption = engine crash** -- capture, dispose owner but
|
|
83
|
+
not-yet-recycled; a raw-pointer `runWithOwner(captured, () => effect(...))`
|
|
84
|
+
splices a child into a disposed owner's `firstOwned`; the next disposal
|
|
85
|
+
walk recurses without termination (`RangeError: Maximum call stack size
|
|
86
|
+
exceeded`). Not a leak; a crash.
|
|
87
|
+
|
|
88
|
+
Both fail on the raw-pointer sketch; both pass on the shipped `describeNode` /
|
|
89
|
+
`liveNode` implementation. Verified against 1.8.0-preview's engine directly:
|
|
90
|
+
`harness/owner-hazard-repro.mjs ./Signal.js` reports `VERDICT: SAFE` on
|
|
91
|
+
the recycled-slot case (continuation runs 2 times before stranger disposal, 3
|
|
92
|
+
times after) and completes the corpse case without stack overflow.
|
|
93
|
+
|
|
94
|
+
Exported as registry methods AND top-level helpers bound to `defaultRegistry`,
|
|
95
|
+
inserted between `createRoot`'s top-level binding and `createScope`'s for
|
|
96
|
+
stable ordering. No hot path touched; sha256 over the 15 other function
|
|
97
|
+
bodies matches pristine 1.8.0-preview byte-for-byte.
|
|
98
|
+
|
|
99
|
+
### Rejected during this cycle (ledger #13)
|
|
100
|
+
|
|
101
|
+
The **"lean node shape" batch-revert side stack** (Reflex pattern C). Moving
|
|
102
|
+
the on-node `{preBatchValue, preBatchVersion, revertEpoch}` triple into a
|
|
103
|
+
registry-level capture stack -- both a parallel-arrays variant AND an
|
|
104
|
+
interleaved stride-3 variant -- held the full behavioral contract (**439/439
|
|
105
|
+
internal tests, conformance clean**) and was VersionMatrix-neutral, but
|
|
106
|
+
regressed capture-dense batched writes **+5-9%** and revert-heavy batches
|
|
107
|
+
**+20%** in cold-process A/B (n=3, consistent).
|
|
108
|
+
|
|
109
|
+
Family (c) loses in **both** directions: these fields are not cold. The first
|
|
110
|
+
batched write is a hot edge (every batch that mutates a signal touches
|
|
111
|
+
`preBatchValue` on the way in), and the on-node triple **already rides
|
|
112
|
+
`node.value`'s cache line** -- no side structure can beat sitting inside the
|
|
113
|
+
line that's about to be loaded anyway. The build is archived under
|
|
114
|
+
`engines/rejected/1_8_0-sidestack.js` with its probe for future reference.
|
|
115
|
+
|
|
116
|
+
### Also measured this cycle (not a 1.8.0 engine property)
|
|
117
|
+
|
|
118
|
+
The **recursive-pull depth plateau is V8-scope-shape-sensitive**. Adding ANY
|
|
119
|
+
context slots to `createRegistry` -- **four dummy consts suffice** -- drops
|
|
120
|
+
the cold-pull overflow point from ~4096 to ~2559 on Node 22 by parking the
|
|
121
|
+
probe on interpreted-size frames. Ceiling scales linearly with
|
|
122
|
+
`--stack-size` on every build. Public claims quoting `~4k depth` should be
|
|
123
|
+
tightened to **"plateau-dependent, 2.5k-4k, tunable"** because the exact
|
|
124
|
+
ceiling is a V8 frame-layout artifact, not an engine constant. Nothing in
|
|
125
|
+
this release changed the pull path; the sensitivity was there in 1.7 too and
|
|
126
|
+
is documented here for the record. `pull-stress.mjs` (1.6+) will pin the
|
|
127
|
+
exact number on any given build.
|
|
128
|
+
|
|
129
|
+
### Hot-path safety
|
|
130
|
+
|
|
131
|
+
**Only `executeEffect` legitimately changed** from 1.7.0-preview -- the
|
|
132
|
+
cleanup-return check is an extra `typeof` + a small append. sha256 over the
|
|
133
|
+
15 other propagation-relevant function bodies (`pullComputed`,
|
|
134
|
+
`markDownstream`, `flushEffects`, `allocateLink`, `severTail`, `createNode`,
|
|
135
|
+
`runCleanup`, `disposeNode`, `createRoot`, `createScope`, `flush`, `batch`,
|
|
136
|
+
`signal`, `computed`, `effect`) matches pristine 1.7.0-preview byte-for-byte.
|
|
137
|
+
|
|
138
|
+
The `getOwner` / `runWithOwner` port only adds new user-API functions between
|
|
139
|
+
`createRoot` and `createScope` -- verified via sha256 that no pre-existing
|
|
140
|
+
function was disturbed by the insertion. Nothing in the propagation core,
|
|
141
|
+
scheduler, or pool moved.
|
|
142
|
+
|
|
143
|
+
### Test coverage
|
|
144
|
+
|
|
145
|
+
- **Full suite green** on 1.8.0-preview with the getOwner/runWithOwner port
|
|
146
|
+
merged in: **451 total**, 440 pass, 0 fail, 1 skip (only the
|
|
147
|
+
architecturally-N/A SSR case in `17-reactivity`), 10 cancelled (the
|
|
148
|
+
`25-devtools-real-boot` cases that need `@zakkster/lite-devtools` installed
|
|
149
|
+
as a peer -- pre-existing, unrelated). Default-mode behavior for effects
|
|
150
|
+
that do not return a function is unchanged from 1.7.0-preview byte-for-byte.
|
|
151
|
+
- **+16 tests in `test/28-run-with-owner.test.mjs`** carried forward from
|
|
152
|
+
1.5.0-beta.2 (basic shape, degradation, and the three hazard pins with
|
|
153
|
+
allocation pressure applied).
|
|
154
|
+
- **`test/03-pool` "stats() shape"** carries the 12-key 1.6+ shape assertion
|
|
155
|
+
forward (`flushPasses` present).
|
|
156
|
+
- **New behavioral coverage to add** for effect cleanup return (deferred to
|
|
157
|
+
`1.8.0-preview.1`): fires before next re-run, fires on dispose,
|
|
158
|
+
composition with `onCleanup(fn)` respects call order, non-function returns
|
|
159
|
+
ignored, self-disposed body registers no cleanup, computed returning a
|
|
160
|
+
function still treats it as the VALUE (regression pin), cleanup exceptions
|
|
161
|
+
do not stop the effect from re-running (or do -- design decision either way
|
|
162
|
+
needs a test).
|
|
163
|
+
|
|
164
|
+
### Verified
|
|
165
|
+
|
|
166
|
+
- **Full engine test suite** green on the merged engine (451 total, 440 pass,
|
|
167
|
+
0 fail, 1 skip, 10 cancelled).
|
|
168
|
+
- **`harness/owner-hazard-repro.mjs ./Signal.js`** reports `VERDICT:
|
|
169
|
+
SAFE` on the recycled-slot case AND completes the corpse case without stack
|
|
170
|
+
overflow -- the ABA guard degrades both hazards to rooted execution as
|
|
171
|
+
designed.
|
|
172
|
+
- **sha256 over 15 pre-existing function bodies** byte-identical between
|
|
173
|
+
pristine 1.8.0-preview and my merged-with-getOwner engine (port added new
|
|
174
|
+
code only). **`executeEffect` sha256** matches between pristine 1.8.0 and
|
|
175
|
+
my merged file too -- the cleanup-return addition survives the port
|
|
176
|
+
unchanged; my port did not touch that function.
|
|
177
|
+
- **`executeEffect` sha256 vs 1.7.0-preview**: `26613285331deaed` ->
|
|
178
|
+
`4487beb9d15f80c6`. Legitimate change; the sole 1.7 -> 1.8 hot-path
|
|
179
|
+
modification.
|
|
180
|
+
- **`markDownstream` / `flushEffects` sha256**: unchanged from 1.7.0-preview
|
|
181
|
+
(still `ad7a007ec23260fc` / `a25b36ba097fdf1a`), which in turn track back
|
|
182
|
+
to 1.6.0-alpha's opcode 6/7 additions. The 1.8 minor introduces no new
|
|
183
|
+
hook-gate branches.
|
|
184
|
+
|
|
185
|
+
### Migration
|
|
186
|
+
|
|
187
|
+
- **Every existing user**: zero work needed. Effects that don't return a
|
|
188
|
+
function are unaffected. `flushStrategy` default remains `"eager"` (1.7's
|
|
189
|
+
byte-identical mode).
|
|
190
|
+
- **Effects that already return a value (e.g. a state update)**: only
|
|
191
|
+
function returns are treated as cleanups. If an effect happens to return a
|
|
192
|
+
function today (rare, but possible), it will now be registered as a
|
|
193
|
+
cleanup. Audit before upgrading if this is your codebase's pattern.
|
|
194
|
+
- **Users of `createRoot` who want capture-and-restore across async
|
|
195
|
+
boundaries**: `getOwner()` + `runWithOwner()` are now on the 1.8 line
|
|
196
|
+
(same signatures and semantics as 1.5.0-beta.2 / 1.6.0-alpha /
|
|
197
|
+
1.7.0-preview).
|
|
198
|
+
|
|
199
|
+
### Tooling, types, and docs
|
|
200
|
+
|
|
201
|
+
- **`Signal.d.ts` now types the cleanup return.** It declared
|
|
202
|
+
`effect(fn: () => void, ...)`, so the headline 1.8.0 feature did not
|
|
203
|
+
typecheck for TypeScript consumers at all -- and `Signal.d.ts` ships in
|
|
204
|
+
`files[]`. Added `EffectCleanup` and `EffectBody` (`() => void |
|
|
205
|
+
EffectCleanup`) and widened both `effect()` signatures (the `Registry`
|
|
206
|
+
method and the top-level export). Verified with `tsc --strict`: returning a
|
|
207
|
+
cleanup typechecks, plain `void` bodies still typecheck (no regression), and
|
|
208
|
+
a computed returning a function still yields the function as its **value**.
|
|
209
|
+
- **Interim behavioral coverage for the cleanup return.** The Test-coverage
|
|
210
|
+
note above defers this feature's tests to a later preview, which left the
|
|
211
|
+
flagship 1.8.0 change shipping unpinned. `harness/smoke.mjs` (which
|
|
212
|
+
**asserts**, and runs first in `harness:all` and `npm run verify`) now
|
|
213
|
+
carries T6-T9: the cleanup fires before the next re-run *and* on dispose; it
|
|
214
|
+
composes with `onCleanup` in call order; non-function returns
|
|
215
|
+
(number/string/null/object/undefined) are ignored without throwing; and a
|
|
216
|
+
computed returning a function still treats it as the VALUE. These are a
|
|
217
|
+
regression pin, not a substitute for the full `test/` cases.
|
|
218
|
+
- **VersionMatrix manifest fixed and moved.** An updated manifest sat at the
|
|
219
|
+
repo root, where the gate never reads it -- `pre-publish.mjs` spawns
|
|
220
|
+
`matrix.sh` with `cwd: harness/VersionMatrix`, and `matrix.sh` `cd`s to its
|
|
221
|
+
own directory, so `./manifest.json` always resolves inside `VersionMatrix/`.
|
|
222
|
+
The gate was therefore still running against the stale `floor: 1.3.0` /
|
|
223
|
+
`rolling: 1.5.0-alpha.1` baselines. Its intent (move the baselines forward)
|
|
224
|
+
is now applied in the file the gate actually reads -- **but not with the
|
|
225
|
+
labels it proposed**: `floor: "1.5.0"` and `rolling: "1.7.0-eager"` are not
|
|
226
|
+
npm-installable (no plain `1.5.0` was ever published, and `1.7.0-eager` is a
|
|
227
|
+
toe-to-toe column label, not a version). `matrix.sh` `swap`s floor/rolling in
|
|
228
|
+
from the registry, so those would have failed before measuring anything.
|
|
229
|
+
Now: `floor: "1.3.0"` (the current `latest` stable anchor) and
|
|
230
|
+
`rolling: "1.7.0-preview.2"` (the `preview` tag -- this candidate's true
|
|
231
|
+
predecessor), with a `_notes` line recording the npm-installable constraint.
|
|
232
|
+
- **The `~5,000 chained computeds` depth claim is retired** from README and
|
|
233
|
+
`llms.txt`, per the "Also measured" finding above. The recursive-pull ceiling
|
|
234
|
+
is a **plateau, not a constant**: 4096 on 1.8.0 at Node 22's default stack
|
|
235
|
+
(overflow at 4097), V8-scope-shape-sensitive, and linear in `--stack-size`
|
|
236
|
+
(measured: `--stack-size=4000` lifts the same engine to 16384). The docs now
|
|
237
|
+
say **plateau-dependent, 2.5k-4k on a default stack, tunable**, and point at
|
|
238
|
+
`npm run profile:pull` to pin it per build.
|
|
239
|
+
|
|
7
240
|
## [1.7.0-preview] -- 2026-07-XX
|
|
8
241
|
|
|
9
242
|
The **flush-strategy minor**, shipping on the `preview` dist-tag while it settles.
|
|
@@ -80,7 +313,7 @@ longer matches and `runWithOwner` degrades to **rooted execution** rather than
|
|
|
80
313
|
adopting the continuation into the recycled slot's new resident. Two hazards on
|
|
81
314
|
the raw-pointer alternative pinned in `test/28-run-with-owner.test.mjs` and
|
|
82
315
|
empirically reproduced against a patched engine via
|
|
83
|
-
`
|
|
316
|
+
`harness/owner-hazard-repro.mjs`:
|
|
84
317
|
|
|
85
318
|
- **Recycled-slot cascade death** -- capture, dispose owner, allocate a stranger
|
|
86
319
|
effect that reuses the slot; a raw-pointer `runWithOwner(captured)` silently
|
|
@@ -94,7 +327,7 @@ empirically reproduced against a patched engine via
|
|
|
94
327
|
|
|
95
328
|
Both fail on the raw-pointer sketch; both pass on the shipped `describeNode` /
|
|
96
329
|
`liveNode` implementation. Verified against 1.7.0-preview's engine directly --
|
|
97
|
-
`
|
|
330
|
+
`harness/owner-hazard-repro.mjs ./Signal.js` reports `VERDICT: SAFE` on the
|
|
98
331
|
recycled-slot case (continuation runs 2 times before stranger disposal, 3
|
|
99
332
|
times after) and completes the corpse case without stack overflow.
|
|
100
333
|
|
|
@@ -182,7 +415,7 @@ production V8 than on this sandbox.
|
|
|
182
415
|
|
|
183
416
|
- **Full engine test suite** green on the merged engine (451 total, 440 pass,
|
|
184
417
|
0 fail, 1 skip, 10 cancelled).
|
|
185
|
-
- **`
|
|
418
|
+
- **`harness/owner-hazard-repro.mjs ./Signal.js`** reports
|
|
186
419
|
`VERDICT: SAFE` on the recycled-slot case AND completes the corpse case
|
|
187
420
|
without stack overflow -- the ABA guard degrades both hazards to rooted
|
|
188
421
|
execution as designed.
|
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
[](https://bundlephobia.com/result?p=@zakkster/lite-signal)
|
|
10
10
|
[](https://www.npmjs.com/package/@zakkster/lite-signal)
|
|
11
11
|
[](https://www.npmjs.com/package/@zakkster/lite-signal)
|
|
12
|
+

|
|
12
13
|

|
|
13
14
|

|
|
14
15
|
[](./LICENSE)
|
|
@@ -485,7 +486,7 @@ A registry-level (and top-level) debug hook for push-based tooling -- the connec
|
|
|
485
486
|
|
|
486
487
|
**1.6.0 -- flush-profiling opcodes.** Opcodes `6` (flush pass) and `7` (effect run in pass) extend the surface to cover the flush dimension lite-devtools 1.2 / lite-studio 1.2 read through `watchAllocations`. The matching `stats().flushPasses` counter (the 12th `stats()` key) advances once per drain pass. Both the counter bump and the opcode dispatch sit behind the same `mutationHook !== null` gate, so when no listener is attached they are inert and `flushPasses` is frozen -- the flush loop is byte-identical to 1.5.0.
|
|
487
488
|
|
|
488
|
-
**Characterization harnesses (`burst-dag.mjs`, `pull-stress.mjs`).** Two
|
|
489
|
+
**Characterization harnesses (`harness/burst-dag.mjs`, `harness/pull-stress.mjs`).** Two standalone harnesses in `harness/` that exercise the 1.6.0 instrumentation against the engine's two main hot paths. `burst-dag.mjs` (`npm run profile:burst`) reproduces Andrii's verbatim strided burst generator (`base = (node*13 + layer*17) % prevW`, `staticFraction = 1`, per-batch pull reads -- his real *layered burst flush warm* shape) and runs it head-to-head against the earlier contiguous-window guess it embeds, using opcodes 5/6/7 plus `stats().flushPasses` to report flush passes, recomputes per node, and per-burst us. The strided topology recomputes ~2x the nodes at ~26% higher us/burst, both single-pass -- so the burst gap is **locality, not redundancy** (ROADMAP S5 closed). It takes the engine path as an argument; the contiguous guess it replaced, with its `burstDagScenario` / `multiPassProbe` exports, is archived in `harness/attic/`. `pull-stress.mjs` (`npm run profile:pull`) is the pull-path companion: binary-searches the recursive-pull depth limit and pins it to a number for the build in front of it (**4096** on 1.8.0 at Node 22's default stack, overflow at 4097). Treat that number as a **plateau, not a constant**: it is V8-scope-shape-sensitive -- adding any context slots to `createRegistry` (four dummy consts suffice) drops it to ~2559 by parking the probe on interpreted-size frames -- and it scales linearly with `--stack-size` (measured: `--stack-size=4000` lifts the same engine to 16384). Quote it as **plateau-dependent, 2.5k-4k on a default stack, tunable**, never as a fixed ceiling. The harness also sweeps cold cost per level across depths to flag any superlinear bookkeeping, and confirms cached reads are O(1) regardless of depth (the 1.1.4 `markEpoch` short-circuit holds). Exports `pullStressScenario` for steady-state gates and `probeOverflow` for the bisection alone; supports both `--kind=callable` and `--kind=box`, which surface a real engine difference (box pulls overflow earlier because `box.get()` adds a prototype-method frame per level). `pull-stress` imports only `../Signal.js` + the public `onGraphMutation` hook and `burst-dag` takes an engine path, so both run against any engine build. Neither is part of `npm test` or the published tarball -- they ship in source for reproducibility.
|
|
489
490
|
|
|
490
491
|
### onCleanup
|
|
491
492
|
|
|
@@ -498,6 +499,38 @@ effect(() => {
|
|
|
498
499
|
|
|
499
500
|
Registers a teardown for the *current* computation. Fires before every re-run and once on dispose. Supports multiple cleanups per scope (they're stored as a flat list, run in registration order). Works inside computeds too -- useful for canceling async work when memos become stale.
|
|
500
501
|
|
|
502
|
+
### Returned cleanup (1.8.0)
|
|
503
|
+
|
|
504
|
+
```ts
|
|
505
|
+
effect(() => {
|
|
506
|
+
const id = setInterval(tick, 100);
|
|
507
|
+
return () => clearInterval(id); // runs before the next re-run, and on dispose
|
|
508
|
+
});
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
Since 1.8.0 an effect body may **return** a cleanup function, the Solid/Vue-compatible form of the same idea (Reflex-study pattern A). It runs at exactly the same points as `onCleanup` -- before every re-run and once on dispose.
|
|
512
|
+
|
|
513
|
+
The two styles **compose in call order**. A returned cleanup is appended after any `onCleanup(fn)` registered inside the same body, using the same append semantics (single fn -> pair array -> push):
|
|
514
|
+
|
|
515
|
+
```ts
|
|
516
|
+
effect(() => {
|
|
517
|
+
onCleanup(() => console.log("first")); // registered first
|
|
518
|
+
return () => console.log("second"); // appended after
|
|
519
|
+
});
|
|
520
|
+
// on re-run/dispose: "first", then "second"
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
Non-function returns are ignored, so `return someValue` from an effect is harmless. A self-disposed body -- one that generation-advances mid-execution -- registers nothing: by the time the return value is inspected, the pool slot may already host a new resident, so the engine checks `node.gen === savedGen` before touching `cleanupFn`.
|
|
524
|
+
|
|
525
|
+
**Computeds are deliberately excluded.** A computed returning a function keeps treating that function as its **value**:
|
|
526
|
+
|
|
527
|
+
```ts
|
|
528
|
+
const c = computed(() => () => "I am the value");
|
|
529
|
+
c()(); // "I am the value" -- NOT invoked as a cleanup
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
There is no analogous inspection on the computed pull path; the check lives inside `executeEffect` and is gated on the effect body's return type. Cost is one `typeof` per effect run, entirely off the mark/pull path -- `executeEffect` is the only function body whose sha256 changed between 1.7.0 and 1.8.0.
|
|
533
|
+
|
|
501
534
|
### dispose
|
|
502
535
|
|
|
503
536
|
```ts
|
|
@@ -723,7 +756,7 @@ These are the questions you'd ask in a code review, with the answers:
|
|
|
723
756
|
- **Computed throws.** The error is cached on the node (`FLAG_HAS_ERROR`) and re-thrown on every subsequent read until a dependency changes. This is symmetric with successful caching.
|
|
724
757
|
- **Dispose during flush.** Effects re-check their generation (`gen`) before running through a scheduler trampoline. If `dispose()` bumped the gen between schedule and execute, the trampoline becomes a no-op. The trampoline closure is cached on the node (v1.2) so repeated re-schedules reuse the same function -- ABA safe under async schedulers.
|
|
725
758
|
- **32-bit version wrap.** Versions are `(... + 1) | 0`, so after 2^31 writes they wrap to a negative number. The comparison `((dep.version - evalVer) | 0) > 0` is wrap-safe -- it works on the *modular distance*, not raw integer ordering.
|
|
726
|
-
- **Deep chain depth.** Computed resolution is recursive in the JS call stack.
|
|
759
|
+
- **Deep chain depth.** Computed resolution is recursive in the JS call stack. The ceiling is a **plateau, not a constant**: ~2.5k-4k deep on Node 22's default stack (4096 measured on 1.8.0), V8-scope-shape-sensitive, and linear in `--stack-size` (`--stack-size=4000` reaches 16384). Run `npm run profile:pull` to pin it for your build and your flags. Chains near that ceiling risk `RangeError: Maximum call stack size exceeded`. Effects use an iterative mark phase, so signal -> effect fan-out has no depth limit other than memory.
|
|
727
760
|
- **`destroy()` after dispose.** `destroy()` bumps every node's generation, so any in-flight scheduled trampolines from before destruction are silently dropped. Closures returned to user code from disposed effects guard with `if (node.flags === 0) return;` -- calling `dispose()` again is a no-op.
|
|
728
761
|
|
|
729
762
|
</details>
|
|
@@ -911,7 +944,7 @@ The cross-framework reactivity suite agrees independently, re-run on **1.3.0** (
|
|
|
911
944
|
- **1.3.0** -- the **pool minor**: node and link pools become growable and incrementally populated. New `prealloc` config (`"eager"` default | `"lazy"`) chooses up-front vs on-demand construction; `onCapacityExceeded: "grow"` extends pools via chunked refill (runs of up to 1024 links / 256 nodes, ledger doubles) bounded by the 16x link ceiling; `maxFlushPasses` is now a public config. Internally the propagation mark phase moved to an intrusive linked-list stack (a `nextMark` field) -- the only node-shape change. The hot paths and public callable API are byte-identical to 1.2.2; steady-state zero-GC is unchanged. *Shipped.*
|
|
912
945
|
- **1.4.0** -- the **observability minor**: `stats()` gains three cumulative lifecycle counters (`totalAllocations`, `totalDisposals`, `poolGrowths`), the surface reserved for it in the 1.2.x/1.3.0 notes. Monotonic over the registry's life, reset by `destroy()`, bumped on the existing acquire/dispose/grow edges -- no hot-path change, no public callable API change. This is what lite-devtools / lite-studio read to chart allocation rate, pool-reuse ratio, and graph churn. Drop-in over 1.3.0. *Shipped (beta).*
|
|
913
946
|
- **1.5.0** -- the **API-surface minor**: two non-callable, allocation-light primitives `signalBox` / `computedBox` land alongside the callable `signal` / `computed` (same `ReactiveNode`, full interop, ~1.7x cheaper construction), and **`createRoot`** lands as the ownership escape hatch the owner tree was designed for (detached scope for lazily spawning long-lived nodes from inside a consumer effect -- the pattern `lite-query` needs). The callable API, hot paths, and `stats()` shape are unchanged; the `24-signalbox` suite (staged since 1.3.0) now runs and passes. *Shipped (alpha).*
|
|
914
|
-
- **Next** --
|
|
947
|
+
- **Next** -- the pull-mode recursion depth limit remains the main outstanding architectural item: computed resolution is recursive in the JS call stack, so the ceiling is a **plateau** (~2.5k-4k on Node 22's default stack; 4096 measured on 1.8.0) that is V8-scope-shape-sensitive and linear in `--stack-size`, rather than a fixed bound. An iterative pull rewrite would move it from a call-stack bound to a heap-bound one -- the same move 1.3.0 made for the mark phase. (`runWithOwner`, previously listed here, shipped in 1.5.0-beta.2 and is carried forward on every line since.)
|
|
915
948
|
|
|
916
949
|
> Note: the retracking rewrite that closes the dynamic-topology gap shipped in **1.1.4**, not a future release. The earlier roadmap that listed it under "v1.2" is superseded.
|
|
917
950
|
|
|
@@ -1156,14 +1189,91 @@ Yes, if your computeFn reads its deps in the same order each invocation. The `cu
|
|
|
1156
1189
|
|
|
1157
1190
|
---
|
|
1158
1191
|
|
|
1192
|
+
## Test harnesses
|
|
1193
|
+
|
|
1194
|
+
Everything under `harness/` is a measurement instrument or a gate. None of it is
|
|
1195
|
+
in `npm test` and none of it is in the published tarball -- it ships in source so
|
|
1196
|
+
every number in this README can be reproduced or falsified.
|
|
1197
|
+
|
|
1198
|
+
### `harness/` -- run-on-demand probes
|
|
1199
|
+
|
|
1200
|
+
One dispatcher (`harness/run.mjs`) routes them; each keeps its own node flags, and
|
|
1201
|
+
paths resolve from the dispatcher so the working directory never matters.
|
|
1202
|
+
|
|
1203
|
+
```bash
|
|
1204
|
+
npm run harness:smoke # 1.7 flushStrategy semantics (eager/sab/manual) -- ASSERTS
|
|
1205
|
+
npm run harness:field # verify + cold-child A/B bench (fieldkit)
|
|
1206
|
+
npm run harness:dispose # creation cost: signal() vs signalBox() vs alien
|
|
1207
|
+
npm run harness:churn # topology-churn-per-recompute (1.11 cone-cache gate)
|
|
1208
|
+
npm run harness:owner # async-gap owner-recycling hazard verdict
|
|
1209
|
+
npm run harness:creation # per-framework createComputations matrix
|
|
1210
|
+
npm run harness:perf # sBench update-group shape: eager vs sab
|
|
1211
|
+
npm run harness:toe # cross-version sweep (needs the private engines/ dir)
|
|
1212
|
+
npm run harness:all # smoke + field + dispose + churn, in sequence
|
|
1213
|
+
npm run profile:burst # burst shape: Andrii strided vs contiguous guess
|
|
1214
|
+
npm run profile:pull # pull depth: per-level cost + exact overflow point
|
|
1215
|
+
```
|
|
1216
|
+
|
|
1217
|
+
`harness:smoke` runs first in `harness:all` and in `npm run verify` because it is
|
|
1218
|
+
the only probe that **asserts**: it fails loudly if `eager` / `sab` / `manual`
|
|
1219
|
+
stop behaving as specified, so a broken engine is caught before the long timed
|
|
1220
|
+
probes spend twenty minutes measuring it.
|
|
1221
|
+
|
|
1222
|
+
`owner-hazard-repro.mjs` is the reproducer cited in the `getOwner` / `runWithOwner`
|
|
1223
|
+
notes (`VERDICT: SAFE` on the shipping engine, `VERDICT: CORRUPTED` on a raw-pointer
|
|
1224
|
+
sketch). `churnprobe.mjs` reads link churn off `onGraphMutation` (opcodes `3`/`4`),
|
|
1225
|
+
not `stats()`, so it reports gross retracking that a net `activeLinks` gauge would
|
|
1226
|
+
hide. `retracking.difftest.mjs` is a differential fuzzer: point it at a previously
|
|
1227
|
+
shipped engine and it asserts both builds agree on every write across thousands of
|
|
1228
|
+
value-dependent topology flips. `dispose` and `creation` compare against
|
|
1229
|
+
`alien-signals`, which is **not** a declared dependency -- without it, `dispose`
|
|
1230
|
+
runs the two lite columns only (`npm i -D alien-signals` unlocks the rest).
|
|
1231
|
+
Settled one-off probes are parked in `harness/attic/`, wired into nothing.
|
|
1232
|
+
|
|
1233
|
+
### `harness/toe-to-toe/` -- cross-version sweep
|
|
1234
|
+
|
|
1235
|
+
Every shipped and in-flight engine measured against every other, in cold
|
|
1236
|
+
processes, on one host -- the tool that separates "1.N got faster" from "the
|
|
1237
|
+
machine got hotter". It fixes three defects in its predecessor: sequential
|
|
1238
|
+
ordering (which made three sha256-*identical* propagation bodies appear to trend
|
|
1239
|
+
across 1.9 -> 1.11 -- a pure thermal artifact) is now round-robin; a `1.6.0-sentinel`
|
|
1240
|
+
column detects mid-run drift; and the silent corrupter -- where only `v17` actually
|
|
1241
|
+
received `flushStrategy: "sab"` while later engines were *labelled* sab and
|
|
1242
|
+
batch-wrapped but built **eager** -- is fixed so the mode decides.
|
|
1243
|
+
|
|
1244
|
+
Its `engines/` directory is **gitignored**: several snapshots are unreleased, so the
|
|
1245
|
+
sweep *script* is public and versioned while the engine source is not. A fresh clone
|
|
1246
|
+
cannot run `harness:toe` until the snapshots are restored. See
|
|
1247
|
+
`harness/toe-to-toe/README.md`.
|
|
1248
|
+
|
|
1249
|
+
### `harness/VersionMatrix/` -- the publish gate
|
|
1250
|
+
|
|
1251
|
+
Cold-process-per-version performance regression gate, wired as `prepublishOnly`.
|
|
1252
|
+
Refuses to render a verdict at all when a capture's rep-to-rep spread exceeds
|
|
1253
|
+
`maxSpreadPct` (**NO EVIDENCE -- RECAPTURE**) rather than mistaking host noise for
|
|
1254
|
+
a regression. Run `npm run calibrate` inside it to measure self-noise before
|
|
1255
|
+
touching any tolerance; tolerances must sit above measured noise, and a hot or
|
|
1256
|
+
thermally-throttling laptop will blow the spread guard long before it blows a
|
|
1257
|
+
tolerance.
|
|
1258
|
+
|
|
1259
|
+
### `harness/ProfilerTools/` -- version-portable hardening suite
|
|
1260
|
+
|
|
1261
|
+
Wired as `npm run test:harness`.
|
|
1262
|
+
|
|
1263
|
+
---
|
|
1264
|
+
|
|
1159
1265
|
## npm scripts
|
|
1160
1266
|
|
|
1161
1267
|
```bash
|
|
1162
1268
|
npm test # behavior suite, ~1.3s
|
|
1163
1269
|
npm run test:gc # zero-gc suite, requires --expose-gc, ~3s
|
|
1270
|
+
npm run test:harness # profiler-tools hardening suite
|
|
1164
1271
|
npm run bench # comparative benchmark vs alien-signals (results.txt), ~5min
|
|
1165
1272
|
npm run bench-reactive # 5-framework reactivity suite (resultsReactive.txt)
|
|
1166
|
-
npm run
|
|
1273
|
+
npm run harness:smoke # flushStrategy semantics -- asserts
|
|
1274
|
+
npm run harness:all # smoke + field + dispose + churn probes
|
|
1275
|
+
npm run gate # cold-process version-matrix regression gate (also runs on prepublish)
|
|
1276
|
+
npm run verify # test + harness:smoke + bench; gate for publish
|
|
1167
1277
|
```
|
|
1168
1278
|
|
|
1169
1279
|
---
|
package/Signal.d.ts
CHANGED
|
@@ -38,6 +38,20 @@ export interface EffectOptions {
|
|
|
38
38
|
/** Idempotent dispose handle returned by {@link effect} and `.subscribe()`. */
|
|
39
39
|
export type Dispose = () => void;
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Cleanup returned from an effect body (1.8.0, Reflex pattern A).
|
|
43
|
+
* Runs before the next re-run and once on dispose, appended after any
|
|
44
|
+
* `onCleanup(fn)` registered in the same body (they compose in call order).
|
|
45
|
+
*/
|
|
46
|
+
export type EffectCleanup = () => void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* An effect body. Returning a function registers it as a cleanup (1.8.0);
|
|
50
|
+
* any other return value is ignored. Computeds are NOT affected -- a computed
|
|
51
|
+
* returning a function keeps treating that function as its value.
|
|
52
|
+
*/
|
|
53
|
+
export type EffectBody = () => void | EffectCleanup;
|
|
54
|
+
|
|
41
55
|
/**
|
|
42
56
|
* Anything that can be passed to {@link Registry.dispose}: a {@link Signal},
|
|
43
57
|
* a {@link Computed}, or an effect's {@link Dispose} function. Passing an
|
|
@@ -262,7 +276,7 @@ export interface RegistryConfig {
|
|
|
262
276
|
export interface Registry {
|
|
263
277
|
signal<T>(initial: T, opts?: SignalOptions<T>): Signal<T>;
|
|
264
278
|
computed<T>(fn: () => T, opts?: ComputedOptions<T>): Computed<T>;
|
|
265
|
-
effect(fn:
|
|
279
|
+
effect(fn: EffectBody, opts?: EffectOptions): Dispose;
|
|
266
280
|
/** Allocation-light, non-callable signal (1.5.0). See {@link SignalBox}. */
|
|
267
281
|
signalBox<T>(initial: T, opts?: SignalOptions<T>): SignalBox<T>;
|
|
268
282
|
/** Allocation-light, non-callable computed (1.5.0). See {@link ComputedBox}. */
|
|
@@ -367,7 +381,7 @@ export function setDefaultRegistry(registry: Registry): void;
|
|
|
367
381
|
|
|
368
382
|
export function signal<T>(initial: T, opts?: SignalOptions<T>): Signal<T>;
|
|
369
383
|
export function computed<T>(fn: () => T, opts?: ComputedOptions<T>): Computed<T>;
|
|
370
|
-
export function effect(fn:
|
|
384
|
+
export function effect(fn: EffectBody, opts?: EffectOptions): Dispose;
|
|
371
385
|
/** Allocation-light, non-callable signal (1.5.0), bound to the default registry. See {@link SignalBox}. */
|
|
372
386
|
export function signalBox<T>(initial: T, opts?: SignalOptions<T>): SignalBox<T>;
|
|
373
387
|
/** Allocation-light, non-callable computed (1.5.0), bound to the default registry. See {@link ComputedBox}. */
|
package/Signal.js
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @zakkster/lite-signal v1.
|
|
2
|
+
* @zakkster/lite-signal v1.8.0-alpha.0 (ledger #18 corrected)
|
|
3
|
+
* Copyright (c) Zahary Shinikchiev <shinikchiev@yahoo.com>
|
|
4
|
+
* MIT License
|
|
5
|
+
* --------------------
|
|
6
|
+
* 1.8.0 -- effect cleanup return (Reflex-study pattern A).
|
|
7
|
+
*
|
|
8
|
+
* NEW: effect(() => { ...; return cleanup }) -- an effect body may return a
|
|
9
|
+
* cleanup function (Solid/Vue/Reflex-compatible), which runs before the next
|
|
10
|
+
* re-run and on dispose. Composes with imperative onCleanup(fn) in call
|
|
11
|
+
* order. Non-function returns are ignored. Zero cost on bodies returning
|
|
12
|
+
* undefined (one typeof check per effect run, off the mark/pull path).
|
|
13
|
+
* Computeds are untouched: a computed returning a function keeps treating it
|
|
14
|
+
* as the VALUE.
|
|
15
|
+
*
|
|
16
|
+
* REJECTED during this cycle (ledger #13, measured): the "lean node shape"
|
|
17
|
+
* batch-revert side stack (Reflex pattern C). Moving the on-node
|
|
18
|
+
* {preBatchValue, preBatchVersion, revertEpoch} triple into a registry-level
|
|
19
|
+
* capture stack -- parallel arrays AND an interleaved stride-3 variant --
|
|
20
|
+
* held the full behavioral contract (439/439, conformance clean) and was
|
|
21
|
+
* VersionMatrix-neutral, but regressed capture-dense batched writes +5-9%
|
|
22
|
+
* and revert-heavy batches +20% in cold-process A/B (n=3, consistent).
|
|
23
|
+
* Family (c) loses in BOTH directions: these fields are not cold -- the
|
|
24
|
+
* first batched write is a hot edge, and the on-node triple already rides
|
|
25
|
+
* node.value's cache line, which no side structure can beat. The build is
|
|
26
|
+
* archived (engines/rejected/1_8_0-sidestack.js) with its probe.
|
|
27
|
+
*
|
|
28
|
+
* ALSO MEASURED (not a 1.8.0 property): the recursive-pull depth plateau is
|
|
29
|
+
* V8-scope-shape-sensitive -- adding ANY context slots to createRegistry
|
|
30
|
+
* (four dummy consts suffice) drops the cold-pull overflow point from ~4096
|
|
31
|
+
* to ~2559 on Node 22 by parking the probe on interpreted-size frames.
|
|
32
|
+
* Ceiling scales linearly with --stack-size on every build. Public claims
|
|
33
|
+
* quoting "~4k depth" should say "plateau-dependent, 2.5k-4k, tunable".
|
|
34
|
+
*
|
|
35
|
+
* 1.7.0 flushStrategy (eager | sab | manual) + r.flush() carry forward
|
|
36
|
+
* unchanged, including the two-closure .set/boxSet build.
|
|
37
|
+
*
|
|
38
|
+
* Original 1.7.0 header follows.
|
|
39
|
+
*
|
|
3
40
|
* --------------------
|
|
4
41
|
* 1.7.0 -- flushStrategy: registry-level effect-delivery policy.
|
|
5
42
|
*
|
|
@@ -23,7 +60,7 @@
|
|
|
23
60
|
* closure captures a constant function reference for its lifetime; V8 inlines the
|
|
24
61
|
* monomorphic target. In "eager" mode the inlined body is byte-identical to the
|
|
25
62
|
* 1.6.0 inline check (`if (batchDepth === 0) flushEffects()`), preserving the
|
|
26
|
-
*
|
|
63
|
+
* section 0b ledger #6 verdict (per-call closure-var loads are forbidden -- a hoisted
|
|
27
64
|
* function reference + monomorphic inlining is not the same mechanism).
|
|
28
65
|
*
|
|
29
66
|
* Original 1.6.0 header follows.
|
|
@@ -906,6 +943,25 @@ export function createRegistry(config) {
|
|
|
906
943
|
* gen-snapshot guard is the v1.2 conformance fix for #141.
|
|
907
944
|
* @private
|
|
908
945
|
*/
|
|
946
|
+
// 1.12.1 (ledger #18): the cleanup-return APPEND LADDER lives here, OUT OF LINE.
|
|
947
|
+
// 1.8.0 inlined all 15 lines of it into executeEffect -- a hot body -- which pushed that
|
|
948
|
+
// body past V8's inline/code-size budget and cost 11-23% on effect-dense graphs
|
|
949
|
+
// (bisected: reverting ONLY that hunk restored 1.7.0 exactly). Same failure mode as
|
|
950
|
+
// ledger #17: BYTES, not instructions. The hot body now carries a single branch --
|
|
951
|
+
// `if (ret !== undefined)` -- and the common case (an effect returning nothing) is one
|
|
952
|
+
// undefined-compare. This cold function is entered only when a body actually returns
|
|
953
|
+
// something, i.e. it rides a branch that is already cold: the counter-placement rule.
|
|
954
|
+
// Semantics are IDENTICAL to 1.8.0: auto-detected (no API change), conditional returns
|
|
955
|
+
// work on any run, composes with imperative onCleanup in call order, and a self-disposed
|
|
956
|
+
// body (gen advanced) registers nothing -- the slot may already host a new resident.
|
|
957
|
+
function registerCleanupReturn(node, ret, savedGen) {
|
|
958
|
+
if (typeof ret !== "function" || node.gen !== savedGen) return;
|
|
959
|
+
const existing = node.cleanupFn;
|
|
960
|
+
if (existing === undefined) node.cleanupFn = ret;
|
|
961
|
+
else if (typeof existing === "function") node.cleanupFn = [existing, ret];
|
|
962
|
+
else existing.push(ret);
|
|
963
|
+
}
|
|
964
|
+
|
|
909
965
|
function executeEffect(node) {
|
|
910
966
|
if ((node.flags & FLAG_COMPUTING) !== 0) throw new Error("CycleError: Infinite effect loop detected.");
|
|
911
967
|
|
|
@@ -953,7 +1009,8 @@ export function createRegistry(config) {
|
|
|
953
1009
|
const savedGen = node.gen;
|
|
954
1010
|
if (mutationHook !== null) mutationHook(5, node.id, 0);
|
|
955
1011
|
try {
|
|
956
|
-
node.computeFn();
|
|
1012
|
+
const ret = node.computeFn();
|
|
1013
|
+
if (ret !== undefined) registerCleanupReturn(node, ret, savedGen);
|
|
957
1014
|
} finally {
|
|
958
1015
|
if (node.gen === savedGen) {
|
|
959
1016
|
severTail(node);
|
|
@@ -1615,7 +1672,7 @@ export function createRegistry(config) {
|
|
|
1615
1672
|
* (`undefined` if called outside any effect/computed body). Companion to
|
|
1616
1673
|
* `runWithOwner`: capture the lifecycle scope now, restore it later --
|
|
1617
1674
|
* typically across an async boundary. Shipped in 1.5.0-beta.2, carried
|
|
1618
|
-
* forward unchanged into 1.6
|
|
1675
|
+
* forward unchanged into 1.6 / 1.7 / 1.8.
|
|
1619
1676
|
*
|
|
1620
1677
|
* The handle is a `describeNode` descriptor stamped with the pool slot's
|
|
1621
1678
|
* generation counter. It is safe to hold across async boundaries: if the
|
|
@@ -1636,7 +1693,7 @@ export function createRegistry(config) {
|
|
|
1636
1693
|
* Run `fn` with `ownerHandle` as the current lifecycle owner. Effects
|
|
1637
1694
|
* or computeds created directly in `fn` are adopted by that owner and
|
|
1638
1695
|
* cascade-dispose when the owner re-runs or is disposed. Shipped in
|
|
1639
|
-
* 1.5.0-beta.2, carried forward unchanged into 1.6
|
|
1696
|
+
* 1.5.0-beta.2, carried forward unchanged into 1.6 / 1.7 / 1.8.
|
|
1640
1697
|
*
|
|
1641
1698
|
* Degradation semantics for handles that cannot be re-attached:
|
|
1642
1699
|
* - `null` / `undefined` -> rooted execution (createRoot semantics for the
|
package/llms.txt
CHANGED
|
@@ -23,6 +23,7 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
|
|
|
23
23
|
- **Untrack**: `untrack(fn)` reads without subscribing.
|
|
24
24
|
- **isTracking**: `isTracking()` returns true iff a read right now would record a dependency on this registry (for wrappers that lazily allocate signals).
|
|
25
25
|
- **onCleanup**: registers teardown for the current computation; fires before each re-run and once on dispose. Works in effects and computeds.
|
|
26
|
+
- **Returned cleanup (1.8.0)**: an EFFECT body may `return` a cleanup function (Solid/Vue/Reflex-compatible). Runs at the same points as onCleanup (before each re-run, once on dispose) and is APPENDED after any onCleanup registered in the same body, so the two styles compose in call order. Non-function returns are ignored; a self-disposed body registers nothing (gen-guarded). COMPUTEDS ARE EXCLUDED: a computed returning a function keeps treating it as the VALUE. Cost: one `typeof` per effect run, off the mark/pull path; `executeEffect` is the only body whose sha256 changed 1.7.0 -> 1.8.0.
|
|
26
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.
|
|
27
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
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.
|
|
@@ -93,7 +94,9 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
|
|
|
93
94
|
report flush passes, max recomputes per node, and per-burst us; also exports
|
|
94
95
|
`burstDagScenario` + `multiPassProbe`. **`pull-stress.mjs`** (`npm run
|
|
95
96
|
profile:pull`) is the pull-path companion: binary-searches the recursive-pull
|
|
96
|
-
depth limit
|
|
97
|
+
depth limit and pins it per engine (4096 on 1.8.0 / Node 22 default stack; a
|
|
98
|
+
PLATEAU, not a constant -- V8-scope-shape-sensitive, and linear in --stack-size,
|
|
99
|
+
which lifts the same engine to 16384 at --stack-size=4000),
|
|
97
100
|
sweeps cold cost per level, confirms cached reads are O(1) via markEpoch;
|
|
98
101
|
exports `pullStressScenario` + `probeOverflow`. Both import only
|
|
99
102
|
`./Signal.js` + public `onGraphMutation`, run against any engine build.
|
|
@@ -661,6 +664,19 @@ function dumpOwnerTree(handle, depth = 0) {
|
|
|
661
664
|
- `bench/dispose-recycle.mjs` -- 1.2.2 targeted microbench: create/dispose/recreate cycle (the free-list invariant audit target).
|
|
662
665
|
- `bench/torture/` -- crash-detection soaks: `graph-fuzzer`, `scheduler-bench`, `torture-soak`. Exit 0 iff zero errors AND post-teardown pool clean.
|
|
663
666
|
- `bench/run-all.sh` + `bench/aggregate.mjs` -- cold-process-per-engine protocol + per-scenario aggregation.
|
|
667
|
+
- `harness/run.mjs` -- dispatcher for the run-on-demand probes (smoke, field, dispose, churn, owner, creation, perf, burst, pull, toe, all).
|
|
668
|
+
- `harness/smoke.mjs` -- 1.7 flushStrategy semantics (eager/sab/manual) + `flush()`, and the 1.8 effect-cleanup-return contract (fires before re-run + on dispose, composes with onCleanup in call order, non-function returns ignored, computed-returning-a-function still yields the VALUE). ASSERTS, so it fails loudly on a regression. First in `harness:all` and `verify`.
|
|
669
|
+
- `harness/perf-probe.mjs` -- sBench update-group shape, eager vs sab, per scenario.
|
|
670
|
+
- `harness/fieldkit.mjs` -- single-file portable verify + cold-child A/B bench across six shapes.
|
|
671
|
+
- `harness/churnprobe.mjs` -- topology-churn-per-recompute via onGraphMutation opcodes 3/4 (link add/sever); the 1.11 cone-cache gate.
|
|
672
|
+
- `harness/burst-dag.mjs` -- burst-shape characterization: Andrii's verbatim strided topology vs the contiguous guess it embeds (ROADMAP S5 closed); takes engine-path arg.
|
|
673
|
+
- `harness/pull-stress.mjs` -- pull-mode depth characterization: per-level cost, overflow depth (4096 on 1.8.0 at Node 22's default stack -- a plateau, not a constant: V8-scope-shape-sensitive and linear in --stack-size), O(1) cached-read; exports pullStressScenario/probeOverflow.
|
|
674
|
+
- `harness/owner-hazard-repro.mjs` -- async-gap owner-recycling hazard verdict (cited by getOwner/runWithOwner).
|
|
675
|
+
- `harness/retracking.difftest.mjs` -- differential retracking fuzzer; takes <reference.js> [candidate.js] and asserts both builds agree under thousands of value-dependent topology flips.
|
|
676
|
+
- `harness/toe-to-toe/` -- cross-version sweep (round-robin ordering, drift sentinel, capability columns). Its `engines/` dir is PRIVATE/gitignored: several snapshots are unreleased.
|
|
677
|
+
- `harness/VersionMatrix/` -- cold-process-per-version regression gate (wired as prepublishOnly); refuses a verdict on unstable captures (NO EVIDENCE) rather than misreading host noise as a regression.
|
|
678
|
+
- `harness/ProfilerTools/` -- profiler-signal x devtools composition harness (wired as test:harness).
|
|
679
|
+
- `harness/attic/` -- parked probes (1.2.0->1.2.1 shape hunt, the superseded contiguous burst-dag, the superseded sbench sweep); wired into nothing.
|
|
664
680
|
- `demo/index.html` -- interactive visualization of the reactive graph.
|
|
665
681
|
|
|
666
682
|
## Install
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakkster/lite-signal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0-alpha.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",
|
|
@@ -29,11 +29,24 @@
|
|
|
29
29
|
"test": "node --test --test-reporter=spec",
|
|
30
30
|
"test:gc": "node --expose-gc --test --test-reporter=spec",
|
|
31
31
|
"test:coverage": "c8 node --test --test-reporter=spec",
|
|
32
|
+
"test:harness": "node --test --test-reporter=spec harness/ProfilerTools/",
|
|
32
33
|
"bench": "node --expose-gc bench/benchmark.mjs",
|
|
33
34
|
"bench-reactive": "node --expose-gc bench/benchmarkReactive.mjs",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
35
|
+
"harness": "node harness/run.mjs",
|
|
36
|
+
"harness:smoke": "node harness/run.mjs smoke",
|
|
37
|
+
"harness:field": "node harness/run.mjs field",
|
|
38
|
+
"harness:dispose": "node harness/run.mjs dispose",
|
|
39
|
+
"harness:churn": "node harness/run.mjs churn",
|
|
40
|
+
"harness:owner": "node harness/run.mjs owner",
|
|
41
|
+
"harness:creation": "node harness/run.mjs creation",
|
|
42
|
+
"harness:perf": "node harness/run.mjs perf",
|
|
43
|
+
"harness:toe": "node harness/run.mjs toe",
|
|
44
|
+
"harness:all": "node harness/run.mjs all",
|
|
45
|
+
"profile:burst": "node --expose-gc harness/burst-dag.mjs ./Signal.js",
|
|
46
|
+
"profile:pull": "node --expose-gc harness/pull-stress.mjs",
|
|
47
|
+
"gate": "node harness/VersionMatrix/pre-publish.mjs",
|
|
48
|
+
|
|
49
|
+
"verify": "npm test && npm run harness:smoke && npm run bench"
|
|
37
50
|
},
|
|
38
51
|
"keywords": [
|
|
39
52
|
"signal",
|
|
@@ -71,6 +84,17 @@
|
|
|
71
84
|
"sideEffects": false,
|
|
72
85
|
"devDependencies": {
|
|
73
86
|
"c8": "^11.0.0",
|
|
74
|
-
"@zakkster/lite-devtools": "^1.1.0"
|
|
87
|
+
"@zakkster/lite-devtools": "^1.1.0",
|
|
88
|
+
"@zakkster/lite-signal": "^1.3.0 || >=1.4.0-beta.0 || >=1.6.0-preview.0",
|
|
89
|
+
"@zakkster/lite-profiler": "^1.1.0",
|
|
90
|
+
"@zakkster/lite-profiler-signal": "^1.2.0"
|
|
91
|
+
},
|
|
92
|
+
"overrides": {
|
|
93
|
+
"@zakkster/lite-time": {
|
|
94
|
+
"@zakkster/lite-signal": "$@zakkster/lite-signal"
|
|
95
|
+
},
|
|
96
|
+
"@zakkster/lite-devtools": {
|
|
97
|
+
"@zakkster/lite-signal": "$@zakkster/lite-signal"
|
|
98
|
+
}
|
|
75
99
|
}
|
|
76
100
|
}
|