@zakkster/lite-signal 1.7.0-preview.0 → 1.8.0-experimental

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/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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zakkster/lite-signal",
3
- "version": "1.7.0-preview.0",
3
+ "version": "1.8.0-experimental",
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",