@zakkster/lite-signal 1.7.0-preview.2 → 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 +233 -71
- package/README.md +35 -3
- package/Signal.d.ts +16 -2
- package/Signal.js +62 -5
- package/llms.txt +6 -3
- package/package.json +2 -2
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.
|
|
@@ -194,77 +427,6 @@ production V8 than on this sandbox.
|
|
|
194
427
|
`createScope` plus updates the return object and adds two top-level exports;
|
|
195
428
|
zero touch on any pre-existing function.
|
|
196
429
|
|
|
197
|
-
### Tooling -- harness wiring, and a benchmark that was measuring nothing
|
|
198
|
-
|
|
199
|
-
**`bench/benchmark.mjs` was producing invalid numbers and is fixed.** Every
|
|
200
|
-
lite-signal adapter in it constructed its registry with `flushStrategy: "sab"`
|
|
201
|
-
while driving un-batched `.set` calls. In SAB mode a `.set` outside `batch()`
|
|
202
|
-
*enqueues* effects but does not flush them, and the harness never called
|
|
203
|
-
`batch()` or `r.flush()` anywhere -- so the effect ran exactly **once** (its
|
|
204
|
-
creation-time run) and never again inside the timed loop. The loop was timing a
|
|
205
|
-
bare mark-dirty against dead-code-eliminated downstream work.
|
|
206
|
-
|
|
207
|
-
The symptom was visible in the reports and went unread: nine of eleven rows
|
|
208
|
-
printed `sink=[ ]` and `BENCH_SINK_SUM (anti-DCE): 0.00`. MUX reported
|
|
209
|
-
**22,032K ops/s** against a real **~219K** -- a ~100x fiction. Measured on the
|
|
210
|
-
same host: as-written `sab`-no-flush = 1 effect run, sink 0; `sab` + explicit
|
|
211
|
-
`r.flush()` = 20,000 runs, 191K ops/s; `eager` = 20,000 runs, 219K ops/s (which
|
|
212
|
-
matches the long-published ~223K MUX figure).
|
|
213
|
-
|
|
214
|
-
- The nine adapters now run **eager**, which is byte-identical to 1.6.0 and the
|
|
215
|
-
only mode comparable to the reference libraries -- alien-signals, preact,
|
|
216
|
-
vue-reactivity and solid all deliver eagerly. SAB is the right mode for
|
|
217
|
-
Andrii's `update*` group (observers but no effects), which is what
|
|
218
|
-
`harness/perf-probe.mjs` and `harness/toe-to-toe/` are for, not this harness.
|
|
219
|
-
- A **VALIDITY GUARD** was added: any scenario finishing with a dead sink now
|
|
220
|
-
prints an `INVALID RUN` block naming the offending rows and sets a non-zero
|
|
221
|
-
exit code. The old code computed the `sink=[x]` / `[ ]` column and then ignored
|
|
222
|
-
it. Silence was the bug.
|
|
223
|
-
- **Every number in `results.txt` and `bench/bench-runs/` predating this fix is
|
|
224
|
-
invalid and must be regenerated.** `bench/benchmarkReactive.mjs` is
|
|
225
|
-
**unaffected**: it also sets `"sab"`, but it drives every write through
|
|
226
|
-
`withBatch(...)`, and batch exit *does* auto-flush in SAB mode -- verified
|
|
227
|
-
clean against 1.7.0 (cellx vectors matched, all internal assertions pass).
|
|
228
|
-
|
|
229
|
-
**Harness wiring restored and extended.** `profile:burst` / `profile:pull`
|
|
230
|
-
pointed at `burst-dag.mjs` / `pull-stress.mjs` in the repo root, where neither
|
|
231
|
-
file has lived since 1.6; both now resolve into `harness/`. The dispatcher
|
|
232
|
-
(`harness/run.mjs`) gained `smoke`, `perf`, `burst`, `pull` and `toe`, and the
|
|
233
|
-
`harness:*` scripts plus `gate` / `prepublishOnly` (VersionMatrix) and
|
|
234
|
-
`test:harness` (ProfilerTools) are wired in `package.json` again. `harness:smoke`
|
|
235
|
-
now leads `harness:all` and `npm run verify`, because it is the only probe that
|
|
236
|
-
**asserts** -- a `flushStrategy` regression fails in a second instead of after
|
|
237
|
-
twenty minutes of timed probes.
|
|
238
|
-
|
|
239
|
-
**Scratch directories folded in.** `tmp/`, `tmp2/` and `tmp3/` are gone:
|
|
240
|
-
|
|
241
|
-
- `tmp3/toe-to-toe.mjs` + `runner.mjs` -> `harness/toe-to-toe/`. This is the
|
|
242
|
-
corrected cross-version sweep and it supersedes the sbench driver: it replaces
|
|
243
|
-
sequential ordering with round-robin (the old loop ran the newest engine last,
|
|
244
|
-
on the hottest chassis, which is why three sha256-**identical** propagation
|
|
245
|
-
bodies appeared to trend across 1.9 -> 1.11), adds a `1.6.0-sentinel` drift
|
|
246
|
-
column, and fixes the **silent corrupter** -- `if (mode === "sab" && engineDir
|
|
247
|
-
=== "v17")` meant only v17 ever received `flushStrategy: "sab"`, while every
|
|
248
|
-
later engine was *labelled* sab and batch-wrapped but built **eager**. Its
|
|
249
|
-
`engines/` dir is gitignored: several snapshots are unreleased, so the sweep
|
|
250
|
-
script is public and the engine source is not.
|
|
251
|
-
- `tmp/sbench-driver.mjs` + `sbench-runner.mjs` -> `harness/attic/` (superseded).
|
|
252
|
-
Their output stands, though: in that sweep v17 was the only `sab` combo, so the
|
|
253
|
-
corrupter was accidentally correct there. Preserved as
|
|
254
|
-
`harness/toe-to-toe/sbench-results-1.7.0.txt`.
|
|
255
|
-
- `tmp2/TESTING-SAB-METHODOLOGY.md` -> `harness/`; `tmp2/sink-check.mjs` ->
|
|
256
|
-
`harness/attic/` (redundant -- `harness/smoke.mjs` covers eager/sab/manual and
|
|
257
|
-
asserts). `tmp/Signal.js` (a stale 1.7.0-WIP snapshot) and the duplicated
|
|
258
|
-
`CHANGELOG-1.7.0.md` / `ROADMAP` copies are dropped.
|
|
259
|
-
- Root loose files cleaned: `owner-hazard-repro.mjs` (a formatting-only duplicate
|
|
260
|
-
of the `harness/` copy) removed; `retracking.difftest.mjs` moved into
|
|
261
|
-
`harness/` and **fixed** -- it imported a hard-coded `./1.1.6.js` that does not
|
|
262
|
-
exist in this tree, so it could not run at all; it now takes
|
|
263
|
-
`<reference.js> [candidate.js]` on the command line.
|
|
264
|
-
|
|
265
|
-
`Signal.js` and the published `files[]` whitelist are untouched by any of the
|
|
266
|
-
above; installed tarballs are byte-identical.
|
|
267
|
-
|
|
268
430
|
## [1.6.0] -- 2026-06-26 (preview)
|
|
269
431
|
|
|
270
432
|
The observability-and-lifecycle minor, shipping on the `preview` dist-tag while it
|
package/README.md
CHANGED
|
@@ -486,7 +486,7 @@ A registry-level (and top-level) debug hook for push-based tooling -- the connec
|
|
|
486
486
|
|
|
487
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.
|
|
488
488
|
|
|
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
|
|
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.
|
|
490
490
|
|
|
491
491
|
### onCleanup
|
|
492
492
|
|
|
@@ -499,6 +499,38 @@ effect(() => {
|
|
|
499
499
|
|
|
500
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.
|
|
501
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
|
+
|
|
502
534
|
### dispose
|
|
503
535
|
|
|
504
536
|
```ts
|
|
@@ -724,7 +756,7 @@ These are the questions you'd ask in a code review, with the answers:
|
|
|
724
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.
|
|
725
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.
|
|
726
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.
|
|
727
|
-
- **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.
|
|
728
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.
|
|
729
761
|
|
|
730
762
|
</details>
|
|
@@ -912,7 +944,7 @@ The cross-framework reactivity suite agrees independently, re-run on **1.3.0** (
|
|
|
912
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.*
|
|
913
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).*
|
|
914
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).*
|
|
915
|
-
- **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.)
|
|
916
948
|
|
|
917
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.
|
|
918
950
|
|
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.
|
|
@@ -662,12 +665,12 @@ function dumpOwnerTree(handle, depth = 0) {
|
|
|
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.
|
|
664
667
|
- `harness/run.mjs` -- dispatcher for the run-on-demand probes (smoke, field, dispose, churn, owner, creation, perf, burst, pull, toe, all).
|
|
665
|
-
- `harness/smoke.mjs` -- 1.7 flushStrategy semantics (eager/sab/manual) + `flush()
|
|
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`.
|
|
666
669
|
- `harness/perf-probe.mjs` -- sBench update-group shape, eager vs sab, per scenario.
|
|
667
670
|
- `harness/fieldkit.mjs` -- single-file portable verify + cold-child A/B bench across six shapes.
|
|
668
671
|
- `harness/churnprobe.mjs` -- topology-churn-per-recompute via onGraphMutation opcodes 3/4 (link add/sever); the 1.11 cone-cache gate.
|
|
669
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.
|
|
670
|
-
- `harness/pull-stress.mjs` -- pull-mode depth characterization: per-level cost,
|
|
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.
|
|
671
674
|
- `harness/owner-hazard-repro.mjs` -- async-gap owner-recycling hazard verdict (cited by getOwner/runWithOwner).
|
|
672
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.
|
|
673
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.
|
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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"profile:burst": "node --expose-gc harness/burst-dag.mjs ./Signal.js",
|
|
46
46
|
"profile:pull": "node --expose-gc harness/pull-stress.mjs",
|
|
47
47
|
"gate": "node harness/VersionMatrix/pre-publish.mjs",
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
"verify": "npm test && npm run harness:smoke && npm run bench"
|
|
50
50
|
},
|
|
51
51
|
"keywords": [
|