@zakkster/lite-signal 1.7.0-preview.1 → 1.8.0-experimental.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 CHANGED
@@ -4,6 +4,198 @@ 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 `Publications/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
+ `Publications/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
+ - **`Publications/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
+
7
199
  ## [1.7.0-preview] -- 2026-07-XX
8
200
 
9
201
  The **flush-strategy minor**, shipping on the `preview` dist-tag while it settles.
package/Signal.js CHANGED
@@ -1,5 +1,42 @@
1
1
  /**
2
- * @zakkster/lite-signal v1.7.0
2
+ * @zakkster/lite-signal v1.8.0
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
- * §0b ledger #6 verdict (per-call closure-var loads are forbidden -- a hoisted
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.
@@ -953,7 +990,22 @@ export function createRegistry(config) {
953
990
  const savedGen = node.gen;
954
991
  if (mutationHook !== null) mutationHook(5, node.id, 0);
955
992
  try {
956
- node.computeFn();
993
+ // 1.8.0 (Reflex pattern A): an effect body may RETURN a cleanup
994
+ // function -- Solid/Vue-compatible ergonomics for the existing
995
+ // imperative onCleanup(fn). The returned fn runs before the next
996
+ // re-run and on dispose, appended with the exact onCleanup append
997
+ // semantics (single fn -> pair array -> push), so the two
998
+ // registration styles compose in call order. Non-function returns
999
+ // are ignored; a self-disposed body (gen advanced) registers
1000
+ // nothing -- the slot may already host a new resident. One typeof
1001
+ // per effect run, entirely off the mark/pull path.
1002
+ const ret = node.computeFn();
1003
+ if (typeof ret === "function" && node.gen === savedGen) {
1004
+ const existing = node.cleanupFn;
1005
+ if (existing === undefined) node.cleanupFn = ret;
1006
+ else if (typeof existing === "function") node.cleanupFn = [existing, ret];
1007
+ else existing.push(ret);
1008
+ }
957
1009
  } finally {
958
1010
  if (node.gen === savedGen) {
959
1011
  severTail(node);
@@ -1615,7 +1667,7 @@ export function createRegistry(config) {
1615
1667
  * (`undefined` if called outside any effect/computed body). Companion to
1616
1668
  * `runWithOwner`: capture the lifecycle scope now, restore it later --
1617
1669
  * typically across an async boundary. Shipped in 1.5.0-beta.2, carried
1618
- * forward unchanged into 1.6 and 1.7.
1670
+ * forward unchanged into 1.6 / 1.7 / 1.8.
1619
1671
  *
1620
1672
  * The handle is a `describeNode` descriptor stamped with the pool slot's
1621
1673
  * generation counter. It is safe to hold across async boundaries: if the
@@ -1636,7 +1688,7 @@ export function createRegistry(config) {
1636
1688
  * Run `fn` with `ownerHandle` as the current lifecycle owner. Effects
1637
1689
  * or computeds created directly in `fn` are adopted by that owner and
1638
1690
  * cascade-dispose when the owner re-runs or is disposed. Shipped in
1639
- * 1.5.0-beta.2, carried forward unchanged into 1.6 and 1.7.
1691
+ * 1.5.0-beta.2, carried forward unchanged into 1.6 / 1.7 / 1.8.
1640
1692
  *
1641
1693
  * Degradation semantics for handles that cannot be re-attached:
1642
1694
  * - `null` / `undefined` -> rooted execution (createRoot semantics for the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zakkster/lite-signal",
3
- "version": "1.7.0-preview.1",
3
+ "version": "1.8.0-experimental.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",
package/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Zahary Shinikchiev
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.