@zakkster/lite-signal 1.5.0-beta.0 → 1.5.0-beta.3
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 +200 -1
- package/README.md +157 -46
- package/Signal.d.ts +55 -0
- package/Signal.js +43 -1
- package/llms.txt +137 -28
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,126 @@ All notable changes to `@zakkster/lite-signal` are documented here.
|
|
|
4
4
|
Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
5
5
|
This project follows [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
-
## [1.5.0] -- 2026-
|
|
7
|
+
## [1.5.0-beta.2] -- 2026-07-XX
|
|
8
|
+
|
|
9
|
+
The re-attach companion to `createRoot`: **`getOwner`** and **`runWithOwner`**
|
|
10
|
+
ship on the same additive-surface story as 1.5.0. **No engine change.** The
|
|
11
|
+
hot-path function bodies (`pullComputed`, `markDownstream`, `executeEffect`,
|
|
12
|
+
`flushEffects`, `allocateLink`, `severTail`, `createNode`, `runCleanup`,
|
|
13
|
+
`disposeNode`) are **verified byte-identical to 1.5.0-beta.1** via sha256 over
|
|
14
|
+
their extracted bodies. The new primitives are ~20 lines of user-API code plus
|
|
15
|
+
two top-level bindings; every read of `currentOwner` still happens at the same
|
|
16
|
+
sites (creation, effect body save/restore, cleanup), and the propagation path
|
|
17
|
+
remains owner-free per the `markDownstream` invariant comment. Drop-in over
|
|
18
|
+
1.5.0-beta.1.
|
|
19
|
+
|
|
20
|
+
### Added -- `getOwner()` and `runWithOwner(ownerHandle, fn)`
|
|
21
|
+
|
|
22
|
+
`getOwner()` returns an **opaque, gen-stamped handle** for the current
|
|
23
|
+
lifecycle owner (or `undefined` outside any effect/computed body).
|
|
24
|
+
`runWithOwner(handle, fn)` runs `fn` with that handle re-installed as the
|
|
25
|
+
current owner: effects and computeds created directly in `fn` are adopted
|
|
26
|
+
by that owner and cascade-dispose when it re-runs or is disposed. Nulls
|
|
27
|
+
the tracking observer for the duration of `fn` (Solid semantics, matching
|
|
28
|
+
`createRoot`'s pairing) so accidental cross-async edges cannot form.
|
|
29
|
+
|
|
30
|
+
The handles use the same `describeNode` / `liveNode` ABA-guard machinery
|
|
31
|
+
that `describe` / `nodeId` / `forEachOwned` / `ownerOf` have used since
|
|
32
|
+
1.2.1: a returned descriptor carries an internal `NODE_GEN` stamp, and
|
|
33
|
+
`runWithOwner` resolves via `liveNode()` which checks that the stamp
|
|
34
|
+
still matches the pool slot's current gen. Stale, null, undefined, or
|
|
35
|
+
non-tracker handles all **degrade to rooted execution** -- `currentOwner`
|
|
36
|
+
set to `null`, `fn` runs, created children survive without adoption, and
|
|
37
|
+
the caller is responsible for their disposal (the same contract as
|
|
38
|
+
`createRoot`).
|
|
39
|
+
|
|
40
|
+
### Fixed -- the two hazards the gen guard exists to prevent
|
|
41
|
+
|
|
42
|
+
The design was originally sketched with raw node pointers -- `getOwner()
|
|
43
|
+
{ return currentOwner; }` and `runWithOwner(node, fn) { const p =
|
|
44
|
+
currentOwner; currentOwner = node; ... }`. That shape is broken in this
|
|
45
|
+
engine because nodes are pooled and the LIFO free list recycles a
|
|
46
|
+
disposed owner's slot into whatever effect/computed is allocated next.
|
|
47
|
+
Two failure modes were empirically reproduced against a 1.5.0-beta
|
|
48
|
+
engine patched with the raw-pointer alternative
|
|
49
|
+
(`Publications/owner-hazard-repro.mjs`):
|
|
50
|
+
|
|
51
|
+
- **Recycled-slot cascade death.** Owner A captured; A disposed; effect B
|
|
52
|
+
allocated (LIFO -> same slot); `runWithOwner(captured)` silently
|
|
53
|
+
adopts the continuation into B; B's re-run cascade-disposes it.
|
|
54
|
+
Measured on the unsafe engine: continuation ran 1 time before
|
|
55
|
+
stranger disposal, 1 time after (should have been 2, then 3).
|
|
56
|
+
- **Corpse adoption = engine crash.** Same capture, slot NOT yet
|
|
57
|
+
recycled; `runWithOwner(captured, () => effect(...))` splices a child
|
|
58
|
+
into a disposed owner's `firstOwned` list; the next disposal walk
|
|
59
|
+
recurses without termination. Measured: `RangeError: Maximum call
|
|
60
|
+
stack size exceeded` at `runCleanup` / `disposeNode`. Not a leak, a
|
|
61
|
+
crash.
|
|
62
|
+
|
|
63
|
+
Both hazards are pinned in `test/28-run-with-owner.test.mjs` and both
|
|
64
|
+
fail on the raw-pointer sketch; both pass on the shipped
|
|
65
|
+
`describeNode` / `liveNode` implementation. The safe implementation
|
|
66
|
+
degrades both hazards to rooted execution (the continuation runs and
|
|
67
|
+
survives independently of any stranger's lifecycle -- the only honest
|
|
68
|
+
semantics for "the scope you captured no longer exists").
|
|
69
|
+
|
|
70
|
+
### Added -- `test/28-run-with-owner.test.mjs`
|
|
71
|
+
|
|
72
|
+
**16 tests**, structured to catch the failure modes above rather than
|
|
73
|
+
just the microtask happy path:
|
|
74
|
+
|
|
75
|
+
- Basic shape (7 tests): `getOwner()` returns undefined outside any
|
|
76
|
+
effect/computed and a descriptor inside; `runWithOwner` adopts a
|
|
77
|
+
nested effect into the captured owner, nulls the tracking observer
|
|
78
|
+
for reads directly in `fn`, returns whatever `fn` returns, restores
|
|
79
|
+
previous owner/observer/tracking on return AND on throw, and nests
|
|
80
|
+
correctly (inner switches, outer unwinds).
|
|
81
|
+
- Degradation (3 tests): `null` / `undefined` / a signal handle all
|
|
82
|
+
degrade to rooted execution and the created effect works normally
|
|
83
|
+
(fires on updates, disposable).
|
|
84
|
+
- Hazard pins (3 tests, plus a composed test): the recycled-slot cascade
|
|
85
|
+
and the corpse-adoption case, each with allocation pressure applied
|
|
86
|
+
BEFORE `runWithOwner` (a stranger effect is created to force slot
|
|
87
|
+
recycling), so the ABA guard is genuinely exercised. A follow-up
|
|
88
|
+
composed test asserts the continuation survives both the stranger's
|
|
89
|
+
re-runs and its disposal.
|
|
90
|
+
|
|
91
|
+
Full test suite on 1.5.0-beta.2: **455 total** (439 pre-existing +
|
|
92
|
+
16 new), 444 pass, 0 fail, 1 skip (SSR N/A), 10 cancelled (the
|
|
93
|
+
`25-devtools-real-boot` cases that need `@zakkster/lite-devtools`
|
|
94
|
+
installed as a peer -- pre-existing, unrelated).
|
|
95
|
+
|
|
96
|
+
### Added -- `Publications/owner-hazard-repro.mjs`
|
|
97
|
+
|
|
98
|
+
A standalone reproducer for the two hazards, callable against any engine
|
|
99
|
+
(`node owner-hazard-repro.mjs <path-to-Signal.js>`). Prints
|
|
100
|
+
`VERDICT: SAFE` on the shipping implementation, `VERDICT: CORRUPTED` +
|
|
101
|
+
a stack overflow on the raw-pointer sketch. Kept in `Publications/`
|
|
102
|
+
alongside the other reproducers rather than under `test/` so it can
|
|
103
|
+
travel to other engines (a candidate 1.6, or a rejected candidate you
|
|
104
|
+
want to confirm) without dragging the whole test tree along.
|
|
105
|
+
|
|
106
|
+
### Verified -- no hot-path change vs 1.5.0-beta.1
|
|
107
|
+
|
|
108
|
+
sha256 over the extracted function bodies of `pullComputed`,
|
|
109
|
+
`markDownstream`, `executeEffect`, `flushEffects`, `allocateLink`,
|
|
110
|
+
`severTail`, `createNode`, `runCleanup`, and `disposeNode` matches
|
|
111
|
+
1.5.0-beta.1 byte-for-byte. `currentOwner` is written by exactly the
|
|
112
|
+
sites that wrote it before (creation adoption, effect-body save/restore,
|
|
113
|
+
cleanup), plus the two new user-API primitives. Propagation
|
|
114
|
+
(`markDownstream`) remains owner-free per its documented invariant.
|
|
115
|
+
|
|
116
|
+
### Not shipped
|
|
117
|
+
|
|
118
|
+
- Watch.js needs no changes -- `watch` / `when` / `whenAsync` create
|
|
119
|
+
effects through the normal path and inherit correct adoption under
|
|
120
|
+
`runWithOwner` automatically. Verified against the safe engine.
|
|
121
|
+
- `runWithOwner` deliberately does NOT accept a callable `signal`
|
|
122
|
+
handle as an "owner" (signals cannot own). It falls through to
|
|
123
|
+
rooted execution instead, matching the shape of every other
|
|
124
|
+
handle-taking introspection API.
|
|
125
|
+
|
|
126
|
+
## [1.5.0-beta.1] -- 2026-06-XX
|
|
8
127
|
|
|
9
128
|
The API-surface minor: two new **non-callable, allocation-light** reactive
|
|
10
129
|
primitives, `signalBox` and `computedBox`, land alongside the existing callable
|
|
@@ -139,6 +258,61 @@ survives consumer re-runs.
|
|
|
139
258
|
cleanly -- detachment costs no auto-cleanup but introduces no leak. Verified
|
|
140
259
|
against the exact lazy-watcher pattern `lite-query` uses.
|
|
141
260
|
|
|
261
|
+
### Added -- VersionMatrix identical-code guard (harness/VersionMatrix/)
|
|
262
|
+
|
|
263
|
+
The regression gate (`harness/VersionMatrix/`, wired into `prepublishOnly` since
|
|
264
|
+
1.4.0) gains an **identical-code guard**: each capture records the sha256 of the
|
|
265
|
+
engine source (`baselines/<label>/engine.sha256`). If the candidate's hash matches
|
|
266
|
+
a baseline's, that axis is running the *same bytes* -- any measured delta is host
|
|
267
|
+
noise, not a regression -- so the gate marks it `SKIP` rather than let variance
|
|
268
|
+
flag a phantom. This is what saves you when you re-version without a code change:
|
|
269
|
+
a `1.5.0-beta.0` that is byte-identical to a published `1.5.0-alpha.1` cannot
|
|
270
|
+
regress against it, and the gate says so structurally instead of failing on a
|
|
271
|
+
noisy median. Genuine code changes produce a different hash and are gated
|
|
272
|
+
normally. Everything else about the harness -- cold-process-per-version,
|
|
273
|
+
LCG-deterministic input, two baselines (floor `1.3.0` + rolling), calibrated
|
|
274
|
+
tolerances (`frame.avg` 5% rolling / 10% floor, `frame.p99` and `phase.write.p99`
|
|
275
|
+
18% / 30%), four workloads mapping to public bench claims -- carries forward
|
|
276
|
+
from 1.4.0. Details in `harness/VersionMatrix/README.md`.
|
|
277
|
+
|
|
278
|
+
### Verified -- fresh 1.5.0-beta bench sweep
|
|
279
|
+
|
|
280
|
+
Both benches were re-run in full on the 1.5.0-beta engine and their outputs
|
|
281
|
+
committed to `bench/results.txt` (isolated propagation, 9 scenarios) and
|
|
282
|
+
`bench/resultsReactive.txt` (cross-framework reactivity, median-of-10, 34
|
|
283
|
+
tests). The 10 raw reactive-suite runs sit under `bench/bench-runs-reactive/
|
|
284
|
+
run_1.txt` ... `run_10.txt` so anyone can re-median independently.
|
|
285
|
+
|
|
286
|
+
- **Propagation bench (results.txt):** lite +48% / +45% / +33% / +29% on the four
|
|
287
|
+
allocation-heavy scenarios (SELECTIVE DAG / DYNAMIC DAG / MUX / SMALL
|
|
288
|
+
SELECTIVE); **LARGE WEB APP flipped into a small lite win (+2%, from -3% on
|
|
289
|
+
1.4.0)** after the alien-signals 3.1.2 -> 3.2.1 bump between sweeps; parity on
|
|
290
|
+
WIDE DENSE (-6%) and KAIROS (-7%); alien ahead on BROADCAST (-12%) and DEEP
|
|
291
|
+
CHAIN (-14%, narrowed from -29% on 1.4.0 for the same alien-version reason
|
|
292
|
+
-- lite's DEEP CHAIN barely moved, 395 -> 398ms). Speed wins vs alien: **5/9**
|
|
293
|
+
(was 4/9); heap wins: 8/9.
|
|
294
|
+
- **Reactive suite (resultsReactive.txt):** fastest of five frameworks on all
|
|
295
|
+
five `dyn` rows (simple +19%, dynamic +16%, large web app +9%, wide dense +6%,
|
|
296
|
+
deep +12%), and **lite now leads alien on ALL 7 `S: updateComputations` rows**
|
|
297
|
+
this sweep (+3% / +6% / +3% / +12% / +3% / +2% / +8%; was 4/7 on 1.4.0).
|
|
298
|
+
- **Andrii Volynets js-reactivity-benchmark position holds at 4th of 15** with
|
|
299
|
+
geomean **79.3ms** (raw log `bench/AndriiVolynetsReactiveBench.log`); lite is
|
|
300
|
+
ahead of 5th-place Preact Signals (99.8) by ~21% -- the gap widened this
|
|
301
|
+
sweep after Preact's own regression on the newer 1.14.2. Top-3 count moved
|
|
302
|
+
from 21/47 (1.3.0 log) -> 23/47 (1.4.0 log) -> **25/47 (1.5.0-beta log)**;
|
|
303
|
+
outright-fastest-of-15 wins fluctuate at the top of a very tight leaderboard
|
|
304
|
+
where alien-signals / reflex / lite trade sub-percent margins per shape (5
|
|
305
|
+
outright wins on 1.4.0, **2 outright wins on 1.5.0-beta** -- `createComputations4to1`
|
|
306
|
+
and `1000x5 - 25 sources (wide dense)`). The stable metric across every
|
|
307
|
+
published sweep is the geomean rank at #4 of 15.
|
|
308
|
+
- **Third-party version bumps** used in this sweep vs 1.4.0: alien-signals
|
|
309
|
+
3.1.2 -> 3.2.1, @preact/signals-core 1.14.1 -> 1.14.2, @vue/reactivity
|
|
310
|
+
3.5.13 -> 3.5.35, solid-js 1.9.12 -> 1.9.13. Any within-lib delta between
|
|
311
|
+
the two sweeps reflects those bumps + host noise, not lite-signal changes:
|
|
312
|
+
1.4.0 -> 1.5.0 hot-path bytes are byte-identical (1.5.0 adds only the
|
|
313
|
+
non-callable box handle shape, which affects construction cost and handle
|
|
314
|
+
ergonomics but not the pooled-node read/write path).
|
|
315
|
+
|
|
142
316
|
## [1.4.0] -- 2026-06-XX
|
|
143
317
|
|
|
144
318
|
The observability minor: `stats()` gains **three cumulative lifecycle counters**
|
|
@@ -195,6 +369,31 @@ with the rest of registry state, so a reused registry reports lifecycle numbers
|
|
|
195
369
|
for its current epoch only. Grown pool *capacity* is retained across `destroy()`
|
|
196
370
|
as before (the reset keeps the arena warm); only the cumulative counts reset.
|
|
197
371
|
|
|
372
|
+
### Added -- VersionMatrix regression gate (harness/VersionMatrix/)
|
|
373
|
+
|
|
374
|
+
A **same-host, cold-process regression gate** for the engine ships alongside the
|
|
375
|
+
observability counters, wired into `prepublishOnly` -- a candidate that regresses
|
|
376
|
+
beyond calibrated tolerances aborts `npm publish` before it starts. Each
|
|
377
|
+
version-x-workload is profiled in its own `node` invocation (V8 never carries
|
|
378
|
+
inline caches or JIT state across versions), fed an identical LCG write sequence
|
|
379
|
+
(delta = engine change, not input), and reduced to a per-metric median-of-N
|
|
380
|
+
(default 5). **Two baselines** gate every publish: a **floor** (never moves;
|
|
381
|
+
"we shall not regress below this line") and a **rolling** baseline (previous
|
|
382
|
+
published version); a candidate must clear BOTH. Tolerances calibrated against
|
|
383
|
+
measured self-noise (`npm run calibrate`): `frame.avg` is the stable anchor at
|
|
384
|
+
5% vs rolling / 10% vs floor (self-noise <=~3%); `frame.p99` and
|
|
385
|
+
`phase.write.p99` sit at 18% / 30% (self-noise up to ~14%, so a p99 fail should
|
|
386
|
+
be re-run to confirm). Four workloads map to public bench claims:
|
|
387
|
+
`reactive-graph-mix` (KAIROS / mol pattern), `deep-chain` (the DEEP CHAIN weak
|
|
388
|
+
spot), `broadcast-fanout` (the BROADCAST fan-out), and `dynamic-dep-churn` (the
|
|
389
|
+
DYNAMIC / SELECTIVE DAG wins). Committed median baselines under
|
|
390
|
+
`harness/VersionMatrix/baselines/` are the public evidence surface (each
|
|
391
|
+
carrying `env` metadata: CPU, node, date); the gate itself always re-captures
|
|
392
|
+
floor / rolling / candidate in the same job so it never diffs across hosts.
|
|
393
|
+
Manifest at `manifest.json` pins the floor (`1.3.0`), the rolling reference, and
|
|
394
|
+
the workload list. Details in `harness/VersionMatrix/README.md`. (The 1.5.0-beta
|
|
395
|
+
identical-code guard extending this gate lands in the 1.5.0 entry above.)
|
|
396
|
+
|
|
198
397
|
### Verified
|
|
199
398
|
|
|
200
399
|
- **Full suite green** against the 1.4.0 engine: 429 tests, 419 pass, 0 fail,
|
package/README.md
CHANGED
|
@@ -15,21 +15,21 @@
|
|
|
15
15
|
|
|
16
16
|
## 4th of 15 on the community reactivity benchmark -- and the only zero-GC engine in the field
|
|
17
17
|
|
|
18
|
-
On the independent [js-reactivity-benchmark](https://github.com/volynetstyle/js-reactivity-benchmark) (Andrii Volynets' fork; 15 reactive libraries, 47 tests), `lite-signal` places **4th overall by geomean (
|
|
18
|
+
On the independent [js-reactivity-benchmark](https://github.com/volynetstyle/js-reactivity-benchmark) (Andrii Volynets' fork; 15 reactive libraries, 47 tests), `lite-signal` places **4th overall by geomean (79.3ms)** -- ahead of 5th-place Preact Signals (99.8) by ~21%, behind only three push-eager engines: alien-signals (45.2), reflex (48.9), and @reactively (59.9). Raw log: [`bench/AndriiVolynetsReactiveBench.log`](./bench/AndriiVolynetsReactiveBench.log) (all 15 x 47 rows, checked in for audit).
|
|
19
19
|
|
|
20
20
|
It is the **only object-pooled, zero-GC engine in the entire field**, and it gets that result without giving up glitch-freedom or lazy evaluation. Against the mainstream reactivity libraries it leads decisively:
|
|
21
21
|
|
|
22
|
-
| vs | lite-signal is |
|
|
22
|
+
| vs | lite-signal is |
|
|
23
23
|
| ---------------------- | -------------- |
|
|
24
24
|
| **@vue/reactivity** | **1.5x faster** |
|
|
25
25
|
| **Signia** | **1.7x faster** |
|
|
26
|
-
| **MobX** | **2.
|
|
27
|
-
| **@solidjs/signals** | **
|
|
28
|
-
| **SolidJS** | **4.
|
|
29
|
-
| Preact Signals | **1.
|
|
30
|
-
| alien-signals | 0.
|
|
26
|
+
| **MobX** | **2.2x faster** |
|
|
27
|
+
| **@solidjs/signals** | **3.2x faster** |
|
|
28
|
+
| **SolidJS** | **4.6x faster** |
|
|
29
|
+
| Preact Signals | **1.26x faster** (~21% ahead) |
|
|
30
|
+
| alien-signals | 0.57x (the field leader) |
|
|
31
31
|
|
|
32
|
-
`lite-signal` finishes **top-3 on
|
|
32
|
+
`lite-signal` finishes **top-3 on 25 of the 47 tests** (up from 23 on the 1.4.0 sweep) and, on this specific run, is **outright fastest of all 15** on two shapes -- `createComputations4to1` (a computed-creation micro where lite narrowly edges alien 7.08ms vs 7.10ms) and the `1000x5 - 25 sources (wide dense)` rectangular DAG (the "wide dense" web-app shape). It comes second on nine more shapes -- `broadPropagation`, `diamond`, `repeatedObservers`, `unstable` propagation, `manySourcesIntoOneComputedEffect` (fan-in), `manySourcesIntoOneDirectEffect`, `molBench` (mixed app graph), the `32x8 - 4 sources - pull` DAG, and the `10x5 - 2 sources - read 20%` simple-component shape. The outright-win count fluctuates between runs at the top of a very tight leaderboard (reflex and alien-signals swept several wide-aggregation shapes on this run that lite held on the 1.4.0 sweep); the stable metric is the geomean rank, which has held at 4th of 15 across every published sweep. The three engines ahead of it are all push-eager designs that allocate on the hot path; `lite-signal` is the only top-4 finisher that allocates **nothing** in steady state. (Note: this suite measures reactivity *libraries* -- Vue's reactivity core, MobX, Solid, Preact Signals, etc. -- not full UI frameworks like React or Angular.)
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
35
|
npm install @zakkster/lite-signal
|
|
@@ -65,6 +65,7 @@ Synchronous, glitch-free, push-pull. No microtask queue, no allocations after wa
|
|
|
65
65
|
- [Edge cases pinned down](#edge-cases-pinned-down)
|
|
66
66
|
- [Benchmarks](#benchmarks)
|
|
67
67
|
- [Testing strategy](#testing-strategy)
|
|
68
|
+
- [Test harnesses](#test-harnesses)
|
|
68
69
|
- [What this is not](#what-this-is-not)
|
|
69
70
|
- [Ecosystem](#ecosystem)
|
|
70
71
|
- [Browser and runtime support](#browser-and-runtime-support)
|
|
@@ -244,6 +245,7 @@ import {
|
|
|
244
245
|
signalBox, computedBox, // 1.5.0 -- allocation-light, non-callable
|
|
245
246
|
batch, untrack, onCleanup, isTracking,
|
|
246
247
|
createRoot, // 1.5.0 -- detached ownership scope
|
|
248
|
+
getOwner, runWithOwner, // 1.5.0-beta.2 -- capture + restore ownership across async gaps
|
|
247
249
|
// Registry / lifecycle
|
|
248
250
|
createRegistry, setDefaultRegistry, dispose, destroy,
|
|
249
251
|
stats, CapacityError,
|
|
@@ -356,7 +358,31 @@ dispose();
|
|
|
356
358
|
|
|
357
359
|
Runs `fn` in a **detached ownership scope** and returns whatever `fn` returns. Effects and computeds created directly inside `fn` are not adopted by the enclosing owner, so they survive the enclosing effect's re-runs and disposal -- there is no parent to auto-dispose them, so the caller is responsible (typically `fn` returns a disposer or the created handle). Both ownership *and* tracking are detached for the duration of `fn`'s direct body; inner effect/computed bodies still establish their own scopes as usual. Mirrors Solid's `createRoot` on the lifecycle axis.
|
|
358
360
|
|
|
359
|
-
The problem it solves: lazily spawning a *long-lived* node from *inside* a consumer effect is otherwise a footgun -- the spawned node is adopted by the consumer, so the consumer's next re-run cascade-disposes it. That is the ownership model working as designed (owned children dispose with their parent); `createRoot` is the sanctioned opt-out. Any consumer that creates a watcher/subscription inside a reactive scope and expects it to outlive that scope wraps the spawn in `createRoot(() => effect(...))` -- `lite-query`'s query-watcher being the first in the ecosystem.
|
|
361
|
+
The problem it solves: lazily spawning a *long-lived* node from *inside* a consumer effect is otherwise a footgun -- the spawned node is adopted by the consumer, so the consumer's next re-run cascade-disposes it. That is the ownership model working as designed (owned children dispose with their parent); `createRoot` is the sanctioned opt-out. Any consumer that creates a watcher/subscription inside a reactive scope and expects it to outlive that scope wraps the spawn in `createRoot(() => effect(...))` -- `lite-query`'s query-watcher being the first in the ecosystem. The companion primitives `getOwner` / `runWithOwner` -- for capturing the current owner and restoring it across an async boundary -- ship in **1.5.0-beta.2**; see the next section.
|
|
362
|
+
|
|
363
|
+
### getOwner / runWithOwner (1.5.0-beta.2)
|
|
364
|
+
|
|
365
|
+
The re-attach half of the ownership escape hatch. `createRoot` detaches; `getOwner` + `runWithOwner` **capture and restore**. Together they give you the Solid-shaped ownership API for the async pattern that comes up whenever you have to leave a synchronous reactive scope, do work, and come back:
|
|
366
|
+
|
|
367
|
+
```javascript
|
|
368
|
+
import { effect, getOwner, runWithOwner, signal } from '@zakkster/lite-signal';
|
|
369
|
+
|
|
370
|
+
const s = signal(0);
|
|
371
|
+
effect(() => {
|
|
372
|
+
const owner = getOwner(); // opaque, gen-stamped handle
|
|
373
|
+
fetch('/data').then(res => res.json()).then(data => {
|
|
374
|
+
runWithOwner(owner, () => { // re-enter the captured scope
|
|
375
|
+
effect(() => { console.log(s(), data); });
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
`getOwner()` returns the current owner as an **opaque, gen-stamped handle** (or `undefined` outside any effect/computed body). `runWithOwner(handle, fn)` runs `fn` with the captured lifecycle scope reinstated: effects and computeds created directly in `fn` are adopted by that owner and cascade-dispose when it re-runs or is disposed. Reads directly in `fn` do not link -- tracking is detached the same way `createRoot` detaches it, so accidental cross-async edges cannot form. Compose with an inner effect if you want tracking under the restored owner.
|
|
382
|
+
|
|
383
|
+
**Handles are safe to hold across async boundaries.** This is where a raw-pointer implementation would corrupt the graph: node objects are pooled and the LIFO free list recycles a disposed owner's slot into whatever effect/computed is allocated next. A stale raw pointer would silently adopt continuations into that stranger. Instead, `getOwner` returns a `describeNode` handle stamped with the pool slot's generation; `runWithOwner` resolves via `liveNode()`, and if the gen has moved (slot recycled) or the handle refers to a signal (not a tracker), it degrades to **rooted execution** -- the continuation runs, stays alive, and is simply not owned by anyone. That is the only honest semantics for "the scope you captured no longer exists": the alternative was a silent cascade-dispose by an unrelated stranger, or, if the slot was disposed but not yet recycled, a `RangeError: Maximum call stack size exceeded` inside the cleanup recursion. Both hazards are pinned in `test/28-run-with-owner.test.mjs` and empirically demonstrated in `Publications/owner-hazard-repro.mjs`.
|
|
384
|
+
|
|
385
|
+
The handles do **not** keep owners alive -- they are snapshots, not references. Node lifetime is controlled by the owner tree, not by outstanding handles.
|
|
360
386
|
|
|
361
387
|
### isTracking
|
|
362
388
|
|
|
@@ -695,25 +721,25 @@ These are the questions you'd ask in a code review, with the answers:
|
|
|
695
721
|
|
|
696
722
|
## Benchmarks
|
|
697
723
|
|
|
698
|
-
Honest numbers, against the same workload, with anti-DCE sinks and verified effect execution. All measurements: Node 22, **2016-era Intel MacBook Pro (4 cores, ~10 yr old hardware)**, **one engine per cold process**, median across reps. Newer/faster machines shift all libs up proportionally; the relative ordering between libs is what matters. Numbers below are
|
|
724
|
+
Honest numbers, against the same workload, with anti-DCE sinks and verified effect execution. All measurements: Node 22, **2016-era Intel MacBook Pro (4 cores, ~10 yr old hardware)**, **one engine per cold process**, median across reps. Newer/faster machines shift all libs up proportionally; the relative ordering between libs is what matters. Numbers below are the **fresh 1.5.0-beta bench sweep** (default `prealloc: "eager"`) vs alien-signals on the same `benchmark.mjs` loop -- the harness reports **median execution time + transient heap** rather than ops/s. 1.5.0's hot paths are byte-identical to 1.4.0 (1.4.0 added three `stats()` counters on existing acquire/dispose/pool-grow edges; 1.5.0 adds the `signalBox` / `computedBox` non-callable handle shape -- cheaper CONSTRUCTION, same pooled-node read/write path -- and `createRoot`, an ownership escape hatch not on the hot path), so steady-state throughput tracks the 1.4.0 measurement within run-to-run noise on this old host. The third-party engine versions used in this sweep bumped from the 1.4.0 sweep (alien-signals 3.1.2 -> 3.2.1, @preact/signals-core 1.14.1 -> 1.14.2, @vue/reactivity 3.5.13 -> 3.5.35, solid-js 1.9.12 -> 1.9.13), so any within-lib delta between the two sweeps reflects those bumps + host noise, not lite-signal changes. Full per-engine tables: [`results.txt`](bench/results.txt) (this propagation suite) and [`resultsReactive.txt`](bench/resultsReactive.txt) (the cross-framework reactivity suite). The 10 raw reactive-suite runs are checked into [`bench/bench-runs-reactive/`](./bench/bench-runs-reactive/) so anyone can re-median them independently.
|
|
699
725
|
|
|
700
726
|
| Scenario | What it stresses | lite-signal | alien-signals | lite vs alien | transient heap (lite / alien) |
|
|
701
727
|
| ---------- | -------------------------------- | ----------- | ------------- | ------------- | ----------------------------- |
|
|
702
|
-
| **SELECTIVE DAG** | sqrt-layered, set churn, 2 read/iter | **
|
|
703
|
-
| **DYNAMIC DAG** | sqrt-layered, FAN=6, read flips each iter | **
|
|
704
|
-
| **MUX** | 256 signals -> 1 sum -> 1 effect (fan-in) | **67 ms** |
|
|
705
|
-
| **SMALL SELECTIVE** | 6 layers × 64 wide, 6 cand / 3 read | **
|
|
706
|
-
| **
|
|
707
|
-
| **
|
|
708
|
-
| **
|
|
709
|
-
| **BROADCAST** | 1 signal -> 1000 effects (fan-out) |
|
|
710
|
-
| **DEEP CHAIN** | 256-deep computed chain -> 1 effect |
|
|
728
|
+
| **SELECTIVE DAG** | sqrt-layered, set churn, 2 read/iter | **4757 ms** | 9166 ms | **+48% faster** | **1.7 MB / 31 MB** (18x less) |
|
|
729
|
+
| **DYNAMIC DAG** | sqrt-layered, FAN=6, read flips each iter | **9630 ms** | 17375 ms | **+45% faster** | **4.3 MB / 26 MB** (6.0x less) |
|
|
730
|
+
| **MUX** | 256 signals -> 1 sum -> 1 effect (fan-in) | **67 ms** | 101 ms | **+33% faster** | **38 KB / 3.9 MB** (104x less) |
|
|
731
|
+
| **SMALL SELECTIVE** | 6 layers × 64 wide, 6 cand / 3 read | **1940 ms** | 2745 ms | **+29% faster** | **0.3 KB / 25.9 MB** (>=25872x less) |
|
|
732
|
+
| **LARGE WEB APP** | 12 layers × ~80 wide, conditional reads | **2800 ms** | 2845 ms | **+2% faster** | **0.3 KB / 41 KB** (41x less) |
|
|
733
|
+
| **WIDE DENSE** | 5 layers × ~200 wide, dense fan-in | 2870 ms | 2719 ms | -6% (parity) | **0.3 KB / 11.6 MB** (>=11605x less) |
|
|
734
|
+
| **KAIROS** | 1 signal -> 1000 computeds -> 1 effect | 1418 ms | 1327 ms | -7% (parity) | 178 KB / 1.0 MB (5.9x less) |
|
|
735
|
+
| **BROADCAST** | 1 signal -> 1000 effects (fan-out) | 1210 ms | 1084 ms | -12% | 72 KB / 21 KB |
|
|
736
|
+
| **DEEP CHAIN** | 256-deep computed chain -> 1 effect | 398 ms | **349 ms** | -14% | 18 KB / 1.8 MB (96x less) |
|
|
711
737
|
|
|
712
738
|
*(lower time = faster; transient heap = average delta-heap per rep, lower = less GC pressure)*
|
|
713
739
|
|
|
714
|
-
**Reading the table:** lite-signal's time wins cluster exactly where its zero-GC design pays off -- the **allocation-heavy dynamic shapes** (**SELECTIVE DAG +48%**, **DYNAMIC DAG +
|
|
740
|
+
**Reading the table:** lite-signal's time wins cluster exactly where its zero-GC design pays off -- the **allocation-heavy dynamic shapes** (**SELECTIVE DAG +48%**, **DYNAMIC DAG +45%**, **SMALL SELECTIVE +29%**), where alien-signals churns the nursery and lite's object pool allocates near-nothing, plus **MUX +33%** (fan-in aggregation). These are the patterns that dominate live UI workloads under input churn: dashboards, scoreboards, HUDs, leaderboards. **LARGE WEB APP** flipped in lite's favor this sweep (+2%, from -3% on 1.4.0 -- alien 3.2.1 slightly slower on this shape than 3.1.2 was); on a ~2800ms base the sign of that parity result depends on the third-party version being measured against. On the cheap, low-allocation **stable** shapes (KAIROS, WIDE DENSE) lite runs at **parity** with alien -- within a 6-7% band inside this old host's run-to-run noise. The two losses are **BROADCAST (-12%)** (pure fan-out, no retracking for the pool to amortize) and **DEEP CHAIN (-14%)**: on a 256-deep computed pipeline alien's flatter representation still wins, though the gap narrowed considerably from -29% on the 1.4.0 sweep because alien-signals 3.2.1 got slower on the 256-deep shape than 3.1.2 was; lite's DEEP CHAIN barely moved between sweeps (395 -> 398ms).
|
|
715
741
|
|
|
716
|
-
On allocation pressure, `lite-signal` wins **8 of 9 scenarios** and is alone in the zero-alloc band: **~0.3 KB** of transient garbage on the stable app shapes (large web app, wide dense, small selective) across the whole run. The contrast is starkest on the dynamic DAGs -- lite allocates 1.
|
|
742
|
+
On allocation pressure, `lite-signal` wins **8 of 9 scenarios** and is alone in the zero-alloc band: **~0.3 KB** of transient garbage on the stable app shapes (large web app, wide dense, small selective) across the whole run. The contrast is starkest on the dynamic DAGs -- lite allocates 1.7-4.3 MB (genuine retracking re-links) where alien-signals allocates 26-31 MB on the same shapes, and that allocation gap is the mechanism behind lite's +45-48% wins there once each engine is measured in isolation. On DEEP CHAIN, alien's transient heap moved from ~903 KB (with alien 3.1.2) to ~1.8 MB (with alien 3.2.1), further widening the heap gap to ~96x -- lite's 18 KB on the same shape is unchanged. The one scenario where lite allocates more is **BROADCAST** (72 KB vs alien's 21 KB), a pure fan-out with no retracking. `prealloc: "lazy"` trades a little extra first-construction allocation on the dynamic shapes for a smaller resident heap and faster cold start; the steady state is identical. preact and solid trail both engines on the dynamic shapes by 1-2 orders of magnitude on transient heap.
|
|
717
743
|
|
|
718
744
|
> Note on the +70.8 KB retained that lite-signal shows on KAIROS specifically: that's the pre-allocated pool sitting in memory holding the live graph (1002 nodes + ~2000 links). The pool *is* the working memory -- see the [Case for object pooling](#case-for-object-pooling) section. On the other benches the graph is small enough that the same pool floats below baseline after GC.
|
|
719
745
|
|
|
@@ -764,6 +790,7 @@ Three tiers, all reproducible.
|
|
|
764
790
|
- **`23-owner-introspection_test.mjs`** -- 1.2.1 owner-tree introspection + effect-disposer regression (22 tests across 4 suites). `ownerOf`: undefined for top-level / garbage input / stale handle; returns the enclosing effect's descriptor for a child created inside an effect body. `forEachOwned`: no-op for handles with no owned children / garbage input / stale handle; iterates owned children as `{id, kind, value}` descriptors. Gen-guarded introspection (ABA fix): `nodeId` / `describe` / `hasObservers` return undefined / false for stale handles; `observeObservers` throws `TypeError`; `forEachObserver` / `forEachSource` are no-ops; descriptors returned by `describeNode` are themselves gen-stamped so a descriptor obtained pre-recycle correctly walks as a no-op post-recycle (the "descriptors are re-walkable handles" contract survives the guard). Plus the 1.2.1 effect-dispose-handle fix: passing the effect's disposer directly to `describe` / `nodeId` / `forEachSource` / `forEachOwned` / `ownerOf` / `hasObservers` works as a first-class introspection handle (pre-fix it was a bare closure and returned `undefined` for a *live* effect); after `fx()` dispose the same handle correctly goes stale on every entry point; the disposer's `NODE_GEN` mirrors the effect node's birthGen exactly.
|
|
765
791
|
- **`24-signalbox_test.mjs`** -- the `signalBox` / `computedBox` allocation-light handle API, **activated in 1.5.0** (committed `{skip:true}` since 1.3.0, now running against the real implementation). 12 tests: box get/set/peek/update, `computedBox` derive + memoize, peek-does-not-track, subscribe fires-and-untracks, box<->callable interop both directions, batch coalescing (including set-then-revert net no-op), dispose with ABA-safety, the `equals` short-circuit, `computedBox.peek`, and the top-level helpers bound to the default registry.
|
|
766
792
|
- **`27-create-root_test.mjs`** -- `createRoot` (1.5.0), the ownership escape hatch. A watcher spawned inside a consumer effect via `createRoot` survives the consumer's re-run (the exact `lite-query` lazy-watcher pattern); the contrast case confirms an *unwrapped* spawn is cascade-disposed; `createRoot` returns `fn`'s value, detaches tracking in `fn`'s direct body while inner effect bodies still track, and composes with box handles.
|
|
793
|
+
- **`28-run-with-owner.test.mjs`** -- `getOwner` / `runWithOwner` (1.5.0-beta.2), the re-attach companion. 16 tests, structured in three groups: basic shape (7 tests: undefined outside, effect/computed inside, restore-on-return, throw-safety, nesting), degradation (3 tests: null / undefined / signal-handle all fall through to rooted execution), and the three **hazard pins** that a raw-pointer implementation fails: (i) recycled-slot cascade -- capture, dispose owner, allocate an effect that reuses the pool slot, `runWithOwner(captured)` must not adopt into the recycled slot's new resident; (ii) corpse adoption -- capture, dispose owner but not-yet-recycled, `runWithOwner(captured, () => effect(...))` must not crash with `RangeError` in the cleanup recursion; (iii) composed -- both together, continuation must survive stranger re-runs AND disposal. All three fail against the naive `getOwner() { return currentOwner; }` shape (empirically verified against a 1.5.0-beta engine patched with the raw-pointer alternative -- `Publications/owner-hazard-repro.mjs`); all three pass with the `describeNode` gen-stamped handle + `liveNode` ABA guard that ships.
|
|
767
794
|
- **`25-devtools-real-boot_test.mjs`** -- Devtools/Studio contract (10 tests). Boots the actual `Devtools.js` against the 1.5.0 engine and exercises all 19 Devtools exports plus the 10 symbols Studio imports from Devtools. Pins the ghost contract: heavy introspection (graph walk, owner-tree, observer descriptors) adds **zero** nodes to the live graph. Catches the real-rig failure mode where importing the package by its own name from a repo whose `package.json` declares `name: "@zakkster/lite-signal"` resolves to the published build instead of the local engine.
|
|
768
795
|
- **`26-free-list-invariant_test.mjs`** -- the 1.2.2 audit's cleanliness pins (3 invariant tests + 1 targeted coverage test). Asserts directly -- by inspecting freshly-allocated nodes through the documented `describe()` -> `NODE_PTR` introspection protocol -- that the `ReactiveNode` constructor and the fresh-pool-growth path initialize the ten fields the audit removed from `createNode` to identical values, so the deleted writes were defending against a state the engine cannot produce on a clean free list. The 4th test covers the swallow-on-self-dispose-then-throw branch in `pullComputed` (the path that lifted branch coverage from 98.07% to 98.43%).
|
|
769
796
|
|
|
@@ -821,10 +848,91 @@ npm run verify # test + test:gc + a sanity bench
|
|
|
821
848
|
|
|
822
849
|
---
|
|
823
850
|
|
|
851
|
+
## Test harnesses
|
|
852
|
+
|
|
853
|
+
Beyond the engine's own test tiers above, `@zakkster/lite-signal` ships **dedicated harnesses** that live in their own subdirectories with their own `package.json` and setup story. They are version-portable, integration-grade, or otherwise too specialised to belong in the in-tree engine suite -- and they are explicitly opt-in for the two run-on-demand harnesses; the VersionMatrix regression gate is wired into `prepublishOnly` so it runs automatically on `npm publish`. Each is a self-contained artifact you can run against any installed engine, or carry into a different repo to verify a claim independently.
|
|
854
|
+
|
|
855
|
+
This section will grow. As future versions ship publications that need specific defensive validation (e.g. a `flushStrategy` ship, a TC39-polyfill ship, a zero-GC public gate, a profiler/observability ship), the corresponding harness lands here.
|
|
856
|
+
|
|
857
|
+
### `test/ProfilerTests/` -- version-portable hardening suite
|
|
858
|
+
|
|
859
|
+
An adversarial, **version-portable** conformance + hardening suite for `@zakkster/lite-signal`. `node:test` only, zero test deps. Each file imports the **bare** package (`@zakkster/lite-signal`), so it resolves to whatever version is installed when run standalone, and self-references through this repo's own package name when run inside the source tree. Advanced cases are **feature-gated**: an older engine skips the cases for APIs it does not have yet, and they light up automatically as the surface grows.
|
|
860
|
+
|
|
861
|
+
Pins the invariants that quietly break reactive engines: glitch-freedom on diamonds, dropping the untaken branch on dynamic dependencies, keeping unobserved computeds lazy, cleanup order, surviving a throwing effect, no leaks under churn, cascade-disposing an ownership scope. The same cases worth asking about in an interview, and the same ones that regress when an engine is re-tuned for speed.
|
|
862
|
+
|
|
863
|
+
```bash
|
|
864
|
+
# Against the local engine (self-references through the root package name):
|
|
865
|
+
npm run test:hardening
|
|
866
|
+
npm run test:hardening:gc
|
|
867
|
+
|
|
868
|
+
# Standalone, against any published version (run from inside test/ProfilerTests):
|
|
869
|
+
cd test/ProfilerTests
|
|
870
|
+
./run-matrix.sh # tests every published line
|
|
871
|
+
./run-matrix.sh 1.3.0 1.4.0 1.5.0-beta.0 # pick versions explicitly
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
The matrix is **ratcheted stricter every release**: a regression in a future version fails loudly, instead of shipping. The README inside the suite (`test/ProfilerTests/README.md`) records the current pass/skip table per published line.
|
|
875
|
+
|
|
876
|
+
### `harness/VersionMatrix/` -- cold-process performance gate
|
|
877
|
+
|
|
878
|
+
A **same-host, cold-process regression gate** for the engine. Turns "did this release regress?" from a judgment call into a checkpoint: the driver swaps each engine version into `node_modules` in its own `node` invocation (so V8 never carries inline caches or JIT state from one version into another), feeds every version an identical LCG write sequence (so a delta is the engine changing, not the input), and reduces N cold samples per version-x-workload to a per-metric median. Wired as `prepublishOnly` -- a regression aborts `npm publish` before it starts.
|
|
879
|
+
|
|
880
|
+
**Two baselines.** A candidate must clear BOTH a **floor** (never moves -- "we shall not regress below this line") AND a **rolling** baseline (the previous published version). Tolerances are calibrated against measured self-noise (`npm run calibrate`): `frame.avg` is the stable anchor (self-noise <=~3%, gated tight at 5% vs rolling / 10% vs floor); `frame.p99` and `phase.write.p99` are jitter-prone (self-noise up to ~14%), so their tolerances sit above that floor (18% rolling / 30% floor) and a p99 fail should be confirmed with a re-run. The two-baseline design catches the blind spot of a fixed floor -- an engine that improves 1.4 -> 1.6 then regresses back to 1.4 levels still clears a 1.3 floor, but fails the rolling gate.
|
|
881
|
+
|
|
882
|
+
**Identical-code guard (new in 1.5.0-beta).** Each capture records the sha256 of the engine source (`baselines/<label>/engine.sha256`). If the candidate's hash matches a baseline's, that axis runs the *same bytes* -- any measured delta is host noise, not a regression -- so the gate **skips** it (shown as `SKIP`) rather than let variance flag a phantom. This is what saves you when you re-version without a code change: a `1.5.0-beta.0` that is byte-identical to a published `1.5.0-alpha.1` cannot regress against it, and the gate says so structurally instead of failing on a noisy median. A genuine code change produces a different hash and is gated normally.
|
|
883
|
+
|
|
884
|
+
**Four workloads**, each mapping to a public bench claim so a change that regresses one shape can't hide behind another:
|
|
885
|
+
|
|
886
|
+
- `reactive-graph-mix` -- general sources -> layer1 -> layer2 + effects (the KAIROS / mol pattern).
|
|
887
|
+
- `deep-chain` -- long linear computed chain (the DEEP CHAIN weak spot).
|
|
888
|
+
- `broadcast-fanout` -- one source -> many leaves (the BROADCAST pattern).
|
|
889
|
+
- `dynamic-dep-churn` -- branch-flipping bodies that retrack every cycle (the DYNAMIC / SELECTIVE DAG wins).
|
|
890
|
+
|
|
891
|
+
Graphs are sized under lite-signal's default 1024-node pool cap; frame cost is scaled by `ITER` (more update cycles), not more nodes.
|
|
892
|
+
|
|
893
|
+
```bash
|
|
894
|
+
npm run calibrate # self-noise: same version twice, per metric
|
|
895
|
+
bash matrix.sh gate <candidate-version> # published candidate vs floor + rolling
|
|
896
|
+
bash matrix.sh gate-self <label> <path> # current-tree candidate (engine path) vs floor + rolling
|
|
897
|
+
node diff.mjs # diagnostic over committed baselines -> matrix-report.json
|
|
898
|
+
node gate.mjs <label> # gate over already-captured baselines (exit 1 on regression)
|
|
899
|
+
npm run gate # what prepublish runs -- gate-self against the current tree
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
Committed median baselines live under `harness/VersionMatrix/baselines/<version>/*.json` (each carrying `env` metadata: CPU, node, date, and the `engine.sha256`). These are the **public evidence surface** -- anyone can rerun and diff -- but the gate always re-captures floor / rolling / candidate in the same job so it never diffs across hosts. Details, including how to add a new version to the matrix, in [`harness/VersionMatrix/README.md`](./harness/VersionMatrix/README.md).
|
|
903
|
+
|
|
904
|
+
### `harness/ProfilerTools/` -- combined profiler + devtools integration
|
|
905
|
+
|
|
906
|
+
A live cross-package harness that points `@zakkster/lite-profiler-signal` and `@zakkster/lite-devtools` at the **same** lite-signal registry and verifies the integration. `profiler-signal` writes coarse frame telemetry into signals (fps, frameP99, frameClass, per-phase p99); a small dashboard effect reads those signals; `devtools` then inspects that live graph **non-perturbingly** (peek + enumerator walks, never adding an observer) and confirms, via the same `stats()` it monitors, that the profiler allocates no new graph nodes in steady state. This is the externally-runnable proof of the zero-GC contract end-to-end: not just on a microbench, but across the actual published package chain consumers install.
|
|
907
|
+
|
|
908
|
+
```bash
|
|
909
|
+
# One-time setup -- pulls peer deps + the engine version the harness targets:
|
|
910
|
+
cd harness/ProfilerTools
|
|
911
|
+
bash setup.sh
|
|
912
|
+
|
|
913
|
+
# Then:
|
|
914
|
+
npm test
|
|
915
|
+
npm run test:gc
|
|
916
|
+
|
|
917
|
+
# Or from the root:
|
|
918
|
+
npm run test:harness
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
The setup script pins specific package versions via tarball install so the harness can be re-run reproducibly without depending on whatever happens to be in the public registry on the day. Treat the setup as a one-time per-checkout cost.
|
|
922
|
+
|
|
923
|
+
### Notes
|
|
924
|
+
|
|
925
|
+
- The hardening suite and the profiler integration do **not** run on `npm test` from the root. They opt in through the `test:hardening` / `test:harness` scripts (and `test:all`, which chains everything).
|
|
926
|
+
- The **VersionMatrix gate**, by contrast, IS wired into `prepublishOnly` -- a regression on the four reference workloads blocks `npm publish`. Diagnostic runs (`node diff.mjs`) are opt-in from the harness directory.
|
|
927
|
+
- All three subdirectories have their own `package.json` with local scripts, so you can also `cd` in and run `npm test` directly -- the root scripts are just shortcuts.
|
|
928
|
+
- The `npm --prefix <dir> test` form used in the root scripts is the cross-platform replacement for `cd && npm test` -- works identically on Linux, macOS, and Windows.
|
|
929
|
+
|
|
930
|
+
---
|
|
931
|
+
|
|
824
932
|
## Performance Trade-offs & Topology Scaling
|
|
825
933
|
|
|
826
934
|
<details>
|
|
827
|
-
<summary>Stable vs dynamic topologies; Andrii Volynets' matrix, the 1.1.4 result, the 1.
|
|
935
|
+
<summary>Stable vs dynamic topologies; Andrii Volynets' matrix, the 1.1.4 result, the 1.5.0 ranking, and the roadmap.</summary>
|
|
828
936
|
|
|
829
937
|
`lite-signal` was built with a strict mandate: **absolute zero garbage collection**. By packing the dependency graph into a flat, pre-allocated memory arena, we eliminate the Scavenger GC pauses that plague 120fps Canvas/WebGL loops.
|
|
830
938
|
|
|
@@ -832,7 +940,7 @@ Through **v1.1.2**, that came with a mathematical trade-off: while memory alloca
|
|
|
832
940
|
|
|
833
941
|
**Andrii Volynets** (author of the phenomenal [Alien Signals](https://github.com/stackblitz/alien-signals)) generously ran `lite-signal` through his advanced topology matrix on the **v1.1.2** engine. Those numbers -- the *pre-rewrite baseline* -- are below, followed by the 1.1.4 result.
|
|
834
942
|
|
|
835
|
-
**1.
|
|
943
|
+
**1.5.0-beta on the official [js-reactivity-benchmark](https://github.com/volynetstyle/js-reactivity-benchmark) (15 libraries, 47 tests):** `lite-signal` holds **4th overall by geomean (79.3ms)**, behind only alien-signals (45.2, the field leader at 0.57x), reflex (48.9), and @reactively (59.9), and **ahead of 5th-place Preact Signals (99.8, ~21%)** -- the Preact gap widened this sweep after Preact's own regression on the newer 1.14.2. It finishes **top-3 on 25 of 47 tests** (up from 23 on 1.4.0). Outright-fastest-of-15 wins fluctuate at the top of a very tight leaderboard where alien-signals, reflex, and lite trade sub-percent margins; on this sweep lite is #1 on `createComputations4to1` (7.08ms vs alien's 7.10ms) and on `1000x5 - 25 sources (wide dense)` (the "large web app / wide dense" pattern). Raw log with all 15 x 47 rows: [`bench/AndriiVolynetsReactiveBench.log`](./bench/AndriiVolynetsReactiveBench.log). The stable metric across every published sweep is the geomean rank at 4th of 15 -- and lite remains the only object-pooled, zero-GC engine in the field.
|
|
836
944
|
|
|
837
945
|
#### 1. Stable Topologies (Fan-in / Fan-out / Broadcast)
|
|
838
946
|
In stable environments (game engines, particle systems, visualizers), `lite-signal` is blisteringly fast and maintains a near-zero allocation profile, keeping frame times perfectly flat -- unchanged through 1.1.4.
|
|
@@ -845,35 +953,38 @@ In stable environments (game engines, particle systems, visualizers), `lite-sign
|
|
|
845
953
|
| **1000x5 (25 sources, wide/dense)** | 304ms | 303ms | 1746ms |
|
|
846
954
|
| **64x6 (selective dynamic DAG)** | 181ms | 196ms | 559ms |
|
|
847
955
|
|
|
848
|
-
*1.
|
|
849
|
-
| Scenario | alien-signals | lite-signal (1.
|
|
956
|
+
*1.5.0-beta (default eager) on the local harness (slow 2016 MacBook, one engine per cold process -- compare within-column, lite vs alien; the approximating scenarios from `bench/benchmark.mjs`):*
|
|
957
|
+
| Scenario | alien-signals | lite-signal (1.5.0-beta) | result |
|
|
850
958
|
| :--- | :--- | :--- | :--- |
|
|
851
|
-
| **SELECTIVE DAG** (sqrt-layered, set churn) |
|
|
852
|
-
| **DYNAMIC DAG** (sqrt-layered, FAN=6) |
|
|
853
|
-
| **SMALL SELECTIVE** (~ 64x6) |
|
|
854
|
-
| **LARGE WEB APP** (~ 1000x12) |
|
|
855
|
-
| **WIDE DENSE** (~ 1000x5) |
|
|
856
|
-
|
|
857
|
-
> **Honest note (1.
|
|
858
|
-
> wins are on the **allocation-heavy** dynamic shapes (SELECTIVE DAG +48%, DYNAMIC
|
|
859
|
-
> +
|
|
860
|
-
> allocates near-nothing.
|
|
861
|
-
>
|
|
862
|
-
>
|
|
863
|
-
>
|
|
864
|
-
>
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
959
|
+
| **SELECTIVE DAG** (sqrt-layered, set churn) | 9166ms | 4757ms | **lite +48%** |
|
|
960
|
+
| **DYNAMIC DAG** (sqrt-layered, FAN=6) | 17375ms | 9630ms | **lite +45%** |
|
|
961
|
+
| **SMALL SELECTIVE** (~ 64x6) | 2745ms | 1940ms | **lite +29%** |
|
|
962
|
+
| **LARGE WEB APP** (~ 1000x12) | 2845ms | 2800ms | **lite +2%** (flipped from -3% on 1.4.0) |
|
|
963
|
+
| **WIDE DENSE** (~ 1000x5) | 2719ms | 2870ms | alien +6% |
|
|
964
|
+
|
|
965
|
+
> **Honest note (1.5.0-beta isolated run):** measured one-engine-per-process, lite-signal's
|
|
966
|
+
> big wins are still on the **allocation-heavy** dynamic shapes (SELECTIVE DAG +48%, DYNAMIC
|
|
967
|
+
> DAG +45%, SMALL SELECTIVE +29%) -- exactly where alien churns the nursery and lite's pool
|
|
968
|
+
> allocates near-nothing. **LARGE WEB APP flipped into a small lite win this sweep** (+2%,
|
|
969
|
+
> from -3% on 1.4.0), attributable to the alien-signals 3.1.2 -> 3.2.1 bump between sweeps;
|
|
970
|
+
> on a ~2800ms base the sign of that parity result depends on which third-party version is
|
|
971
|
+
> in the other column. 1.5.0's hot paths are byte-identical to 1.4.0 (1.5.0 adds the
|
|
972
|
+
> `signalBox` / `computedBox` non-callable handle plus `createRoot`, none of which move
|
|
973
|
+
> steady-state throughput), so these match the 1.4.0 isolated numbers within noise -- not
|
|
974
|
+
> engine changes. lite remains the only zero-alloc library on every stable scenario
|
|
975
|
+
> (see [`results.txt`](bench/results.txt)).
|
|
976
|
+
|
|
977
|
+
The cross-framework reactivity suite agrees independently, re-run on **1.5.0-beta** (default eager, median-of-10, isolated): lite-signal is the **fastest of five frameworks on all five `dyn` rows** -- `dyn: large web app` **539ms** (+9% vs alien-signals' 593ms) and `dyn: wide dense` **874ms** (+6% vs 932ms), plus simple component (+19%), dynamic component (+16%), and deep (+12%) -- with preact 6-19x slower and vue 15-32x slower on the app-shaped graphs (see [`resultsReactive.txt`](bench/resultsReactive.txt); the 10 raw runs are checked into [`bench/bench-runs-reactive/`](./bench/bench-runs-reactive/)). **Lite now leads alien on all 7 `S: updateComputations` micro-rows** as well this sweep (was 4/7 on 1.4.0) -- +3% / +6% / +3% / +12% / +3% / +2% / +8% across the family, with the exact per-row numbers in `resultsReactive.txt`. The retracking is verified correct by `retracking.difftest.mjs` -- 20,000 direct + 10,000 batched writes, 0 disagreements against the **published 1.1.5** reference (re-pinned for v1.2).
|
|
978
|
+
|
|
979
|
+
**The Takeaway:** as of 1.1.4 you no longer have to choose, and 1.5.0-beta holds the line -- the engine still ranks **4th of 15** on the official js-reactivity-benchmark (the only zero-GC library in the field). `lite-signal` keeps the zero-GC, flat-arena profile for 120fps Canvas/WebGL **and** wins decisively on the high-churn dynamic and fan-in topologies that dominate live UI -- the shapes where zero allocation pays off most. LARGE WEB APP flipped into a small lite win this sweep after the alien-signals 3.2.1 bump; it runs at parity with alien on the other cheap stable shapes. The one shape where alien's flatter representation still leads is the 256-deep computed pipeline (DEEP CHAIN, -14% on the 1.5.0-beta isolated run -- the gap narrowed from -29% on 1.4.0, again because alien 3.2.1 got slower on that specific shape, not because lite improved).
|
|
869
980
|
|
|
870
981
|
### Roadmap
|
|
871
982
|
- **1.1.5** -- additions in service of `lite-devtools` (node identity/traversability on the introspection walkers, for full auto-discovered graph rendering). *Shipped.*
|
|
872
983
|
- **1.2.0** -- the **ownership hybrid**: an owner tree so nested effects/computeds auto-dispose with their parent (closes conformance #209 / #210, matching Solid's `createRoot` ergonomics). Plus three additive features built on the same internal split: pre-batch revert (`batch(() => { a.set(99); a.set(10); })` doesn't re-fire), multi-throw `AggregateError`, and scheduler-thunk caching with an ABA gen guard. *Shipped.*
|
|
873
984
|
- **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.*
|
|
874
|
-
- **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.*
|
|
875
|
-
- **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 (
|
|
876
|
-
- **Next** --
|
|
985
|
+
- **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. Also adds the `harness/VersionMatrix/` regression gate (cold-process, same-host, two baselines) as a `prepublish` step, so a release that regresses `frame.avg` on the four reference workloads (reactive-graph-mix, deep-chain, broadcast-fanout, dynamic-dep-churn) fails the publish. Drop-in over 1.3.0. *Shipped.*
|
|
986
|
+
- **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. VersionMatrix gains an **identical-code guard** (SHA-256 of the engine source per baseline): a re-versioned publish with byte-identical `Signal.js` is marked `SKIP` structurally rather than flagged by noisy median variance. *Shipped (beta).* **1.5.0-beta.2** adds the re-attach companions **`getOwner` / `runWithOwner`** (gen-stamped handles that degrade to rooted execution when the captured owner has been recycled -- the raw-pointer alternative would silently adopt continuations into the recycled slot's new resident, or crash the engine with unbounded cleanup recursion on a corpse handle; both hazards pinned in `test/28-run-with-owner.test.mjs`). Hot paths remain byte-identical to 1.5.0-beta.1 -- verified via sha256 over extracted function bodies (`pullComputed`, `markDownstream`, `executeEffect`, `flushEffects`, `allocateLink`, `severTail`, `createNode`, `runCleanup`, `disposeNode`).
|
|
987
|
+
- **Next** -- the pull-mode recursion depth limit (~5,000 chained computeds) remains the main outstanding architectural item. Watching lite-query's real-world adoption of `createRoot` + `runWithOwner` for what the next escape hatch needs to be.
|
|
877
988
|
|
|
878
989
|
> 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.
|
|
879
990
|
|
package/Signal.d.ts
CHANGED
|
@@ -268,6 +268,49 @@ export interface Registry {
|
|
|
268
268
|
* effect (e.g. a query watcher). Returns whatever `fn` returns.
|
|
269
269
|
*/
|
|
270
270
|
createRoot<T>(fn: () => T): T;
|
|
271
|
+
/**
|
|
272
|
+
* Return the currently-active owner as an opaque, gen-stamped handle
|
|
273
|
+
* (`undefined` if called outside any effect/computed body). Companion to
|
|
274
|
+
* {@link runWithOwner}: capture the current lifecycle scope now, restore
|
|
275
|
+
* it later (typically across an async boundary). Introduced in 1.5.0-beta.2.
|
|
276
|
+
*
|
|
277
|
+
* The handle is a plain descriptor object (same shape as {@link describe}
|
|
278
|
+
* returns) stamped with an internal generation counter. It is safe to
|
|
279
|
+
* hold across async boundaries: if the captured owner is disposed and
|
|
280
|
+
* its pool slot is subsequently recycled by an unrelated effect/computed,
|
|
281
|
+
* the generation counter no longer matches and {@link runWithOwner}
|
|
282
|
+
* treats the handle as stale (degrades to rooted execution). This is the
|
|
283
|
+
* ABA guard already used by `describe` / `nodeId` / `forEachOwned`.
|
|
284
|
+
*
|
|
285
|
+
* The handle does NOT keep the owner alive -- it is a snapshot, not a
|
|
286
|
+
* reference. Node lifetime is controlled by the owner tree, not by
|
|
287
|
+
* outstanding handles.
|
|
288
|
+
*/
|
|
289
|
+
getOwner(): Owner;
|
|
290
|
+
/**
|
|
291
|
+
* Run `fn` with `ownerHandle` as the current lifecycle owner. Effects
|
|
292
|
+
* or computeds created directly in `fn` are adopted by that owner and
|
|
293
|
+
* cascade-dispose when the owner re-runs or is disposed. Introduced in
|
|
294
|
+
* 1.5.0-beta.2.
|
|
295
|
+
*
|
|
296
|
+
* Degradation semantics for handles that cannot be re-attached:
|
|
297
|
+
* - `null` / `undefined` -> rooted execution (createRoot semantics for
|
|
298
|
+
* ownership; created children survive, caller disposes them).
|
|
299
|
+
* - stale handle (owner disposed, slot recycled) -> rooted execution.
|
|
300
|
+
* Never adopts into the unrelated new resident of the recycled slot;
|
|
301
|
+
* never adopts into a corpse (a disposed owner whose slot is not yet
|
|
302
|
+
* recycled).
|
|
303
|
+
* - handle for a live signal (not an effect/computed) -> rooted
|
|
304
|
+
* execution (signals cannot own).
|
|
305
|
+
*
|
|
306
|
+
* Nulls the tracking observer for the duration of `fn` (the same pairing
|
|
307
|
+
* as {@link createRoot}): reads directly inside `fn` do NOT link into any
|
|
308
|
+
* enclosing observer. Inner effect/computed bodies still establish their
|
|
309
|
+
* own owner + observer scopes.
|
|
310
|
+
*
|
|
311
|
+
* Returns whatever `fn` returns.
|
|
312
|
+
*/
|
|
313
|
+
runWithOwner<T>(ownerHandle: Owner, fn: () => T): T;
|
|
271
314
|
/**
|
|
272
315
|
* Universal disposal for anything created by this registry: signals,
|
|
273
316
|
* computeds, boxes, or effect dispose handles. Cross-registry calls are
|
|
@@ -348,6 +391,18 @@ export function signalBox<T>(initial: T, opts?: SignalOptions<T>): SignalBox<T>;
|
|
|
348
391
|
export function computedBox<T>(fn: () => T, opts?: ComputedOptions<T>): ComputedBox<T>;
|
|
349
392
|
/** Run `fn` in a detached ownership scope (1.5.0), bound to the default registry. See {@link Registry.createRoot}. */
|
|
350
393
|
export function createRoot<T>(fn: () => T): T;
|
|
394
|
+
/**
|
|
395
|
+
* An owner handle -- an opaque descriptor returned by {@link getOwner},
|
|
396
|
+
* safe to hold across async boundaries. A stale, null, or non-tracker
|
|
397
|
+
* handle degrades cleanly in {@link runWithOwner} (rooted execution)
|
|
398
|
+
* rather than adopting into an unrelated recycled slot. See
|
|
399
|
+
* {@link Registry.getOwner} for the ABA-guard mechanics. 1.5.0-beta.2+.
|
|
400
|
+
*/
|
|
401
|
+
export type Owner = NodeDescriptor | undefined;
|
|
402
|
+
/** Capture the current owner as an opaque, gen-stamped handle (1.5.0-beta.2), bound to the default registry. See {@link Registry.getOwner}. */
|
|
403
|
+
export function getOwner(): Owner;
|
|
404
|
+
/** Run `fn` under a captured owner handle (1.5.0-beta.2), bound to the default registry. See {@link Registry.runWithOwner}. */
|
|
405
|
+
export function runWithOwner<T>(ownerHandle: Owner, fn: () => T): T;
|
|
351
406
|
/** Universal disposal -- see {@link Registry.dispose}. */
|
|
352
407
|
export function dispose(api: Disposable): void;
|
|
353
408
|
export function batch<T>(fn: () => T): T;
|
package/Signal.js
CHANGED
|
@@ -1457,6 +1457,25 @@ export function createRegistry(config) {
|
|
|
1457
1457
|
* Mirrors Solid's `createRoot` for the lifecycle axis. Returns whatever
|
|
1458
1458
|
* `fn` returns (typically a disposer or the created handle).
|
|
1459
1459
|
*/
|
|
1460
|
+
function getOwner() {
|
|
1461
|
+
return currentOwner !== null ? describeNode(currentOwner) : undefined;
|
|
1462
|
+
}
|
|
1463
|
+
function runWithOwner(ownerHandle, fn) {
|
|
1464
|
+
const node = liveNode(ownerHandle);
|
|
1465
|
+
const prevOwner = currentOwner;
|
|
1466
|
+
const prevObserver = currentObserver;
|
|
1467
|
+
const prevTracking = isTrackingDeps;
|
|
1468
|
+
currentOwner = (node !== undefined && (node.flags & (FLAG_COMPUTED | FLAG_EFFECT)) !== 0) ? node : null;
|
|
1469
|
+
currentObserver = null;
|
|
1470
|
+
isTrackingDeps = false;
|
|
1471
|
+
try {
|
|
1472
|
+
return fn();
|
|
1473
|
+
} finally {
|
|
1474
|
+
currentOwner = prevOwner;
|
|
1475
|
+
currentObserver = prevObserver;
|
|
1476
|
+
isTrackingDeps = prevTracking;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1460
1479
|
function createRoot(fn) {
|
|
1461
1480
|
const prevOwner = currentOwner;
|
|
1462
1481
|
const prevObserver = currentObserver;
|
|
@@ -1697,7 +1716,7 @@ export function createRegistry(config) {
|
|
|
1697
1716
|
while (l !== null) { const nx = l.nextDep; fn(describeNode(l.source)); l = nx; }
|
|
1698
1717
|
}
|
|
1699
1718
|
|
|
1700
|
-
return {signal, computed, effect, signalBox, computedBox, dispose, batch, untrack, createRoot, onCleanup, stats, destroy, isTracking, hasObservers, observeObservers, forEachObserver, forEachSource, forEachOwned, ownerOf, nodeId, describe, onGraphMutation};
|
|
1719
|
+
return {getOwner, runWithOwner, signal, computed, effect, signalBox, computedBox, dispose, batch, untrack, createRoot, onCleanup, stats, destroy, isTracking, hasObservers, observeObservers, forEachObserver, forEachSource, forEachOwned, ownerOf, nodeId, describe, onGraphMutation};
|
|
1701
1720
|
}
|
|
1702
1721
|
|
|
1703
1722
|
// -----------------------------------------------------------------
|
|
@@ -1745,6 +1764,29 @@ export function createRoot(fn) {
|
|
|
1745
1764
|
return defaultRegistry.createRoot(fn);
|
|
1746
1765
|
}
|
|
1747
1766
|
|
|
1767
|
+
/**
|
|
1768
|
+
* Return the currently-active owner as an opaque, gen-stamped handle
|
|
1769
|
+
* (undefined if outside any effect/computed body). Pass to
|
|
1770
|
+
* {@link runWithOwner} to re-enter the captured lifecycle scope. The handle
|
|
1771
|
+
* is safe to hold across async boundaries: it goes STALE when the captured
|
|
1772
|
+
* owner is disposed and the pool slot is recycled, and stale handles
|
|
1773
|
+
* degrade to rooted execution rather than adopting into a stranger.
|
|
1774
|
+
*/
|
|
1775
|
+
export function getOwner() {
|
|
1776
|
+
return defaultRegistry.getOwner();
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
/**
|
|
1780
|
+
* Run `fn` with `ownerHandle` as the lifecycle owner: effects/computeds
|
|
1781
|
+
* created directly in `fn` are adopted by that owner. A null/undefined/stale
|
|
1782
|
+
* handle degrades to rooted execution (created children survive; the caller
|
|
1783
|
+
* disposes them). Nulls the tracking observer for the duration of `fn`.
|
|
1784
|
+
* See {@link Registry.runWithOwner}.
|
|
1785
|
+
*/
|
|
1786
|
+
export function runWithOwner(ownerHandle, fn) {
|
|
1787
|
+
return defaultRegistry.runWithOwner(ownerHandle, fn);
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1748
1790
|
/**
|
|
1749
1791
|
* True iff a read RIGHT NOW would record a dependency on the default registry.
|
|
1750
1792
|
* See {@link createRegistry} for the per-registry version.
|
package/llms.txt
CHANGED
|
@@ -17,7 +17,8 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
|
|
|
17
17
|
- **Computed**: lazy memoized derivation. `computed(fn, { equals? })`. Cache hits return in O(deps) (version comparison only). Cache misses re-run the body and refresh `evalVersion`. Errors are cached via `FLAG_HAS_ERROR` and re-thrown on every read until a dep changes.
|
|
18
18
|
- **Effect**: side-effect runner. `effect(fn, { scheduler? })`. Runs immediately on creation, then on any tracked dep change. Returns a dispose function. Optional scheduler defers execution (e.g., to rAF, microtask, custom frame loop).
|
|
19
19
|
- **Box (1.5.0)**: non-callable, allocation-light variants. `signalBox(initial, { equals? })` returns `{ get, set, peek, update, subscribe }`; `computedBox(fn, { equals? })` returns `{ get, peek, subscribe }` (no set/update -- derived). Same `ReactiveNode` and zero-GC read/write path as the callable forms, full interop in one graph (a callable can read `box.get()` and vice versa). Construction is ~1.7x cheaper than the callable (an `Object.create(proto)` handle, not a closure). Built on a shared prototype from the start -- never `setPrototypeOf` (which would deopt the method-call ICs to megamorphic). Exported as registry methods and top-level helpers.
|
|
20
|
-
- **createRoot (1.5.0)**: `createRoot(fn)` runs `fn` in a detached ownership scope and returns `fn`'s value. Effects/computeds created directly in `fn` are NOT adopted by the enclosing owner, so they survive its re-runs/disposal (the caller owns their lifecycle). Both ownership and tracking are detached for `fn`'s direct body; inner effect/computed bodies still establish their own scopes. The escape hatch for lazily spawning a long-lived node from inside a consumer effect (e.g. `lite-query`'s query-watcher) -- without it, the consumer owns the watcher and cascade-disposes it on its next re-run. Mirrors Solid's `createRoot`.
|
|
20
|
+
- **createRoot (1.5.0)**: `createRoot(fn)` runs `fn` in a detached ownership scope and returns `fn`'s value. Effects/computeds created directly in `fn` are NOT adopted by the enclosing owner, so they survive its re-runs/disposal (the caller owns their lifecycle). Both ownership and tracking are detached for `fn`'s direct body; inner effect/computed bodies still establish their own scopes. The escape hatch for lazily spawning a long-lived node from inside a consumer effect (e.g. `lite-query`'s query-watcher) -- without it, the consumer owns the watcher and cascade-disposes it on its next re-run. Mirrors Solid's `createRoot`.
|
|
21
|
+
- **getOwner / runWithOwner (1.5.0-beta.2)**: the re-attach companion. `getOwner()` returns the current lifecycle owner as an opaque gen-stamped handle (`undefined` outside any effect/computed body); `runWithOwner(handle, fn)` runs `fn` with that owner reinstated so effects/computeds created directly in `fn` are adopted by it (and cascade-dispose when it re-runs). Nulls the tracking observer for `fn`'s direct body (same pairing as `createRoot`). Handles are **safe to hold across async boundaries**: they use the `describeNode` / `liveNode` ABA-guard machinery (`NODE_GEN` stamp checked against the pool slot's current gen), so stale handles -- owner disposed, slot recycled by an unrelated effect via the LIFO free list -- degrade to rooted execution rather than corrupting the graph. A raw-pointer implementation would (i) silently adopt continuations into the recycled slot's new resident (measured: continuation dies with a stranger on its next disposal), or (ii) crash the engine with `RangeError: Maximum call stack size exceeded` on a corpse handle (owner disposed, slot not yet recycled -- the disposal walk recurses without termination). Both hazards pinned in `test/28-run-with-owner.test.mjs`, empirically reproduced via `Publications/owner-hazard-repro.mjs`. Also exported as registry methods + top-level helpers.
|
|
21
22
|
- **dispose(api)**: universal disposal. Accepts a signal, computed, or effect dispose handle; idempotent; cross-registry calls are silent no-ops (per-registry `Symbol("node_ptr")` keys the node-identity slot on the returned API function, foreign signals fail the lookup and fall through). Passing an unrelated value is also safe; passing an arbitrary function invokes it (effect-handle contract).
|
|
22
23
|
- **Batch**: `batch(fn)` defers effect flush until the outermost batch closes. Nestable.
|
|
23
24
|
- **Untrack**: `untrack(fn)` reads without subscribing.
|
|
@@ -52,7 +53,62 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
|
|
|
52
53
|
|
|
53
54
|
## Version notes
|
|
54
55
|
|
|
55
|
-
- **1.5.0-
|
|
56
|
+
- **1.5.0-beta.2** (current): the re-attach companion to `createRoot`.
|
|
57
|
+
**`getOwner()`** and **`runWithOwner(ownerHandle, fn)`** land as registry
|
|
58
|
+
methods + top-level bindings. **No engine change** from 1.5.0-beta.1 -- the
|
|
59
|
+
hot-path function bodies (`pullComputed`, `markDownstream`, `executeEffect`,
|
|
60
|
+
`flushEffects`, `allocateLink`, `severTail`, `createNode`, `runCleanup`,
|
|
61
|
+
`disposeNode`) are byte-identical (sha256-verified over extracted bodies).
|
|
62
|
+
The two new primitives are ~20 lines of user-API code + two top-level
|
|
63
|
+
bindings; `currentOwner` is read/written at the same sites as before
|
|
64
|
+
(creation adoption, effect-body save/restore, cleanup) plus the two new
|
|
65
|
+
wrappers. Drop-in over 1.5.0-beta.1.
|
|
66
|
+
|
|
67
|
+
**Handles are gen-stamped, not raw pointers.** `getOwner()` returns a
|
|
68
|
+
`describeNode` handle stamped with the pool slot's `NODE_GEN`;
|
|
69
|
+
`runWithOwner` resolves via `liveNode()` (the same ABA-guard machinery
|
|
70
|
+
`describe` / `nodeId` / `forEachOwned` / `ownerOf` have used since 1.2.1).
|
|
71
|
+
Stale, null, undefined, or non-tracker (signal) handles all degrade to
|
|
72
|
+
**rooted execution**: `currentOwner` set to `null`, `fn` runs, created
|
|
73
|
+
children survive without adoption, caller disposes them (same contract
|
|
74
|
+
as `createRoot`). This matters because node objects are pooled and the
|
|
75
|
+
LIFO free list recycles a disposed owner's slot into the next
|
|
76
|
+
effect/computed allocated. A raw-pointer alternative
|
|
77
|
+
(`getOwner() { return currentOwner; }`) fails two hazards, both pinned
|
|
78
|
+
in `test/28-run-with-owner.test.mjs` and empirically reproduced by
|
|
79
|
+
`Publications/owner-hazard-repro.mjs`:
|
|
80
|
+
(i) **Recycled-slot cascade death** -- owner A captured; A disposed;
|
|
81
|
+
stranger B allocated (LIFO -> A's slot); `runWithOwner(captured)`
|
|
82
|
+
silently adopts continuation into B; B's next re-run
|
|
83
|
+
cascade-disposes it. Measured on the unsafe engine: continuation
|
|
84
|
+
ran 1 time before stranger disposal, 1 time after (should be 2
|
|
85
|
+
then 3).
|
|
86
|
+
(ii) **Corpse adoption = engine crash** -- capture; A disposed; slot
|
|
87
|
+
NOT yet recycled; `runWithOwner(captured, () => effect(...))`
|
|
88
|
+
splices a child into a disposed owner's `firstOwned`; next
|
|
89
|
+
disposal walk recurses without termination.
|
|
90
|
+
`RangeError: Maximum call stack size exceeded` at `runCleanup` /
|
|
91
|
+
`disposeNode`. Not a leak; a crash.
|
|
92
|
+
Both hazards degrade to rooted execution on the shipped implementation.
|
|
93
|
+
|
|
94
|
+
**Semantics.** `runWithOwner` nulls the tracking observer + tracking flag
|
|
95
|
+
for the duration of `fn` (same pairing `createRoot` uses). Reads directly
|
|
96
|
+
in `fn` do not link to any enclosing observer; if the caller wants
|
|
97
|
+
tracking under the restored owner, they nest an inner effect/computed in
|
|
98
|
+
`fn` which establishes its own scope. Returns whatever `fn` returns.
|
|
99
|
+
Restores previous owner/observer/tracking triplet on return AND on
|
|
100
|
+
throw. Signal handles are rejected (`runWithOwner(signalHandle, fn)` ->
|
|
101
|
+
rooted execution) because signals cannot own -- the `flags & (FLAG_COMPUTED
|
|
102
|
+
| FLAG_EFFECT)` check gates adoption. `getOwner()` returns `undefined`
|
|
103
|
+
(not `null`) outside any effect/computed body to match the shape of the
|
|
104
|
+
other handle-taking APIs. **Tests:** 455 total (439 pre-existing + 16
|
|
105
|
+
new), 444 pass, 0 fail, 1 skip (SSR N/A), 10 cancelled (`25-devtools-
|
|
106
|
+
real-boot` cases needing the devtools peer dep -- pre-existing).
|
|
107
|
+
**Watch.js needs no changes**: `watch` / `when` / `whenAsync` create
|
|
108
|
+
effects through the normal path and inherit correct adoption under
|
|
109
|
+
`runWithOwner` automatically.
|
|
110
|
+
|
|
111
|
+
- **1.5.0-beta.1** (was "current" before beta.2): the **API-surface minor**. Two non-callable,
|
|
56
112
|
allocation-light primitives -- `signalBox(initial, opts?)` returning
|
|
57
113
|
`{ get, set, peek, update, subscribe }` and `computedBox(fn, opts?)` returning
|
|
58
114
|
`{ get, peek, subscribe }` -- land alongside the callable `signal` / `computed`,
|
|
@@ -84,6 +140,53 @@ triggering write -- no `queueMicrotask`, no promises, no scheduler ticks.
|
|
|
84
140
|
tests in `test/27-create-root_test.mjs`). **Coverage:** `Signal.js`
|
|
85
141
|
100% statements / 97.35% branches / 100% functions / 100% lines; `Watch.js` 100%.
|
|
86
142
|
Drop-in over 1.4.0.
|
|
143
|
+
**VersionMatrix (identical-code guard, new in 1.5.0-beta):** the
|
|
144
|
+
`harness/VersionMatrix/` regression gate now records the sha256 of the engine
|
|
145
|
+
source at every capture (`baselines/<label>/engine.sha256`). If the candidate's
|
|
146
|
+
hash matches a baseline's, that axis runs the *same bytes* and the gate marks
|
|
147
|
+
it `SKIP` rather than let variance flag a phantom regression. Genuine code
|
|
148
|
+
changes produce a different hash and are gated normally. Everything else about
|
|
149
|
+
the harness -- cold-process-per-version, LCG-deterministic input, two baselines
|
|
150
|
+
(floor `1.3.0` + rolling `1.5.0-alpha.1`), calibrated tolerances (`frame.avg`
|
|
151
|
+
5% rolling / 10% floor, `frame.p99` and `phase.write.p99` 18% / 30%), four
|
|
152
|
+
workloads mapping to public bench claims -- carries forward from 1.4.0. Wired
|
|
153
|
+
as `prepublishOnly`.
|
|
154
|
+
**Bench position** (third-party
|
|
155
|
+
[js-reactivity-benchmark](https://github.com/volynetstyle/js-reactivity-benchmark),
|
|
156
|
+
15 frameworks, 47 tests; fresh 1.5.0-beta run, raw log
|
|
157
|
+
`bench/AndriiVolynetsReactiveBench.log`): #4 by geomean (79.3) at 1.75x behind
|
|
158
|
+
alien-signals (1.00x, 45.2), reflex (1.08x, 48.9), @reactively (1.33x, 59.9);
|
|
159
|
+
ahead of 5th-place Preact Signals (99.8, lite ~21% ahead -- the gap widened
|
|
160
|
+
after Preact's own regression on the newer 1.14.2 in this sweep). The only
|
|
161
|
+
object-pooled zero-GC engine in the field. Ahead of @vue/reactivity (1.5x),
|
|
162
|
+
Signia (1.7x), MobX (2.2x), @solidjs/signals (3.2x), SolidJS (4.6x). Top-3 on
|
|
163
|
+
25/47 tests (up from 23 on 1.4.0). Outright winners this sweep (rank 1 of all
|
|
164
|
+
15) on TWO shapes: `createComputations4to1` (a computed-creation micro; lite
|
|
165
|
+
edges alien 7.08ms vs 7.10ms) and `1000x5 - 25 sources (wide dense)` (the
|
|
166
|
+
"large web app / wide dense" pattern from the propagation bench). Rank 2 on
|
|
167
|
+
another nine shapes (broadPropagation, diamond, repeatedObservers, unstable
|
|
168
|
+
propagation, `manySourcesIntoOneComputedEffect`, `manySourcesIntoOneDirectEffect`,
|
|
169
|
+
`molBench`, `32x8 - 4 sources - pull`, and `10x5 - 2 sources - read 20%` simple
|
|
170
|
+
component). The outright-win count fluctuates
|
|
171
|
+
at the top of a very tight leaderboard where alien-signals, reflex, and lite
|
|
172
|
+
trade sub-percent margins per shape (1.4.0 sweep had lite outright on 5
|
|
173
|
+
shapes; this sweep 2); the geomean rank at #4 has held across every published
|
|
174
|
+
sweep and is the honest stable metric. (The suite measures reactivity
|
|
175
|
+
libraries -- Vue reactivity core, MobX, Solid, Preact Signals -- not full UI
|
|
176
|
+
frameworks like React/Angular.)
|
|
177
|
+
In the community reactive suite (median-of-10, raw runs in
|
|
178
|
+
`bench/bench-runs-reactive/run_1.txt` ... `run_10.txt`), fastest of 5
|
|
179
|
+
frameworks on the entire `dyn:*` family (the realistic large-DOM-framework
|
|
180
|
+
shapes): dyn: simple 433.17ms (+19% vs alien), dynamic 311.74ms (+16%), large
|
|
181
|
+
web app 539.05ms (+9%), wide dense 874.01ms (+6%), deep 333.06ms (+12%).
|
|
182
|
+
**Lite now leads alien on ALL 7 `S: updateComputations` rows this sweep**
|
|
183
|
+
(+3%/+6%/+3%/+12%/+3%/+2%/+8%; was 4/7 on 1.4.0). Behind on the
|
|
184
|
+
construction-cost path (`S: createComputations*`, `cellx`, `createDataSignals`).
|
|
185
|
+
Third-party engine versions bumped since the 1.4.0 sweep (alien-signals
|
|
186
|
+
3.1.2 -> 3.2.1, @preact/signals-core 1.14.1 -> 1.14.2, @vue/reactivity
|
|
187
|
+
3.5.13 -> 3.5.35, solid-js 1.9.12 -> 1.9.13); any within-lib delta reflects
|
|
188
|
+
those bumps + host noise, not lite-signal changes (1.4.0 -> 1.5.0 hot paths
|
|
189
|
+
are byte-identical).
|
|
87
190
|
|
|
88
191
|
- **1.4.0** (drop-in over 1.3.0): the **observability minor**. `stats()` gains three
|
|
89
192
|
cumulative lifecycle counters -- `totalAllocations`, `totalDisposals`,
|
|
@@ -328,6 +431,9 @@ function effect(fn: () => void, opts?: { scheduler?: (run: () => void) => void }
|
|
|
328
431
|
function signalBox<T>(initial: T, opts?: { equals?: (a: T, b: T) => boolean }): SignalBox<T>; // 1.5.0
|
|
329
432
|
function computedBox<T>(fn: () => T, opts?: { equals?: (a: T, b: T) => boolean }): ComputedBox<T>; // 1.5.0
|
|
330
433
|
function createRoot<T>(fn: () => T): T; // 1.5.0 -- detached ownership scope; returns fn's value
|
|
434
|
+
type Owner = NodeDescriptor | undefined; // 1.5.0-beta.2 -- opaque, gen-stamped handle; safe across async gaps
|
|
435
|
+
function getOwner(): Owner; // 1.5.0-beta.2 -- undefined outside any effect/computed body
|
|
436
|
+
function runWithOwner<T>(ownerHandle: Owner, fn: () => T): T; // 1.5.0-beta.2 -- stale/null/signal-handle -> rooted execution
|
|
331
437
|
function dispose(api: Signal<any> | Computed<any> | SignalBox<any> | ComputedBox<any> | Dispose): void;
|
|
332
438
|
function batch<T>(fn: () => T): T;
|
|
333
439
|
function untrack<T>(fn: () => T): T;
|
|
@@ -470,42 +576,45 @@ None of these touch the reactive engine -- no `FLAG_WATCHER` on `ReactiveNode`,
|
|
|
470
576
|
|
|
471
577
|
The deliberate engineering for `watch`'s "0 per fire" is the hoisted `untrackedFire` closure with `currentNewValue` shared mutable state -- see source comment in `watch.js`. Inline arrow function inside the effect body would allocate per fire and break the zero-GC contract.
|
|
472
578
|
|
|
473
|
-
## Benchmark snapshot (Node 22, 2016-era Intel MacBook Pro, default eager, median across reps -- @1.
|
|
579
|
+
## Benchmark snapshot (Node 22, 2016-era Intel MacBook Pro, default eager, median across reps -- @1.5.0-beta.0)
|
|
474
580
|
|
|
475
581
|
`benchmark.mjs` head-to-head vs alien-signals on app-shaped scenarios (time = median
|
|
476
582
|
execution; heap = average transient delta-heap per rep; lite-signal numbers are
|
|
477
|
-
@1.
|
|
583
|
+
@1.5.0-beta.0, hot paths byte-identical to 1.4.0 -- 1.5.0 adds only the
|
|
584
|
+
`signalBox` / `computedBox` non-callable handle and `createRoot`, neither on the
|
|
585
|
+
steady-state read/write path; third-party engines bumped since 1.4.0 sweep --
|
|
586
|
+
alien-signals 3.1.2 -> 3.2.1 in particular):
|
|
478
587
|
|
|
479
588
|
| Scenario | lite vs alien (time) | transient heap (lite / alien) |
|
|
480
589
|
| -------------------------------- | -------------------- | ----------------------------- |
|
|
481
|
-
| SELECTIVE DAG (set churn) | **+48% faster** | 1.
|
|
482
|
-
| DYNAMIC DAG (FAN=6, read flips) | **+
|
|
483
|
-
| MUX (256 sigs -> sum -> effect) | **+
|
|
484
|
-
| SMALL SELECTIVE (~64x6) | **+29% faster** | 0.3 KB /
|
|
485
|
-
|
|
|
486
|
-
|
|
|
487
|
-
|
|
|
488
|
-
| BROADCAST (1 -> 1000 effects) | -
|
|
489
|
-
| DEEP CHAIN (256-deep -> effect) | -
|
|
590
|
+
| SELECTIVE DAG (set churn) | **+48% faster** | 1.7 MB / 31 MB |
|
|
591
|
+
| DYNAMIC DAG (FAN=6, read flips) | **+45% faster** | 4.3 MB / 26 MB |
|
|
592
|
+
| MUX (256 sigs -> sum -> effect) | **+33% faster** | 38 KB / 3.9 MB |
|
|
593
|
+
| SMALL SELECTIVE (~64x6) | **+29% faster** | 0.3 KB / 25.9 MB |
|
|
594
|
+
| LARGE WEB APP (~1000x12) | **+2% faster** | 0.3 KB / 41 KB |
|
|
595
|
+
| WIDE DENSE (~1000x5) | -6% (parity) | 0.3 KB / 11.6 MB |
|
|
596
|
+
| KAIROS (1 -> 1000 computeds) | -7% (parity) | 178 KB / 1.0 MB |
|
|
597
|
+
| BROADCAST (1 -> 1000 effects) | -12% | 72 KB / 21 KB |
|
|
598
|
+
| DEEP CHAIN (256-deep -> effect) | -14% | 18 KB / 1.8 MB |
|
|
490
599
|
|
|
491
600
|
lite-signal's time wins are the allocation-heavy dynamic shapes (object pool allocates
|
|
492
601
|
near-nothing; alien churns the nursery), plus MUX fan-in aggregation -- the patterns
|
|
493
|
-
that dominate live UI under input churn.
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
The cross-framework reactivity suite (5 frameworks) re-run on 1.
|
|
602
|
+
that dominate live UI under input churn. LARGE WEB APP flipped into a small lite win
|
|
603
|
+
this sweep (+2%, was -3% on 1.4.0) after the alien 3.1.2 -> 3.2.1 bump. Parity on
|
|
604
|
+
WIDE DENSE / KAIROS (within run-to-run noise on this old host). Two losses: BROADCAST
|
|
605
|
+
(pure fan-out, no retracking for the pool to amortize) and DEEP CHAIN (alien's flatter
|
|
606
|
+
representation still wins on long chains, though the gap narrowed from -29% on 1.4.0
|
|
607
|
+
to -14% here -- alien 3.2.1 got slower on 256-deep, lite's DEEP CHAIN barely moved).
|
|
608
|
+
On allocation, lite wins 8/9 scenarios and is alone in the zero-alloc band (~0.3 KB
|
|
609
|
+
transient on the stable app shapes).
|
|
610
|
+
|
|
611
|
+
The cross-framework reactivity suite (5 frameworks) re-run on 1.5.0-beta (default eager,
|
|
503
612
|
median-of-10): lite-signal is fastest on all five `dyn:*` rows -- `dyn: large web app`
|
|
504
|
-
|
|
505
|
-
simple component (+
|
|
506
|
-
slower and vue 15-32x slower on the app-shaped graphs. On the
|
|
507
|
-
|
|
508
|
-
|
|
613
|
+
539ms (+9% vs alien-signals' 593ms), `dyn: wide dense` 874ms (+6% vs 932ms), plus
|
|
614
|
+
simple component (+19%), dynamic component (+16%), deep (+12%) -- with preact 6-19x
|
|
615
|
+
slower and vue 15-32x slower on the app-shaped graphs. On the `S: updateComputations`
|
|
616
|
+
micro-rows **lite now leads alien on ALL 7 rows this sweep** (+3% / +6% / +3% / +12% /
|
|
617
|
+
+3% / +2% / +8%; was 4/7 on 1.4.0). Retracking verified correct by
|
|
509
618
|
`retracking.difftest.mjs` (20,000 direct + 10,000 batched writes, 0 disagreements vs
|
|
510
619
|
published 1.1.5). `prealloc: "lazy"` trades a little first-construction allocation on the
|
|
511
620
|
dynamic shapes for a smaller resident heap and faster cold start; steady state identical.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakkster/lite-signal",
|
|
3
|
-
"version": "1.5.0-beta.
|
|
3
|
+
"version": "1.5.0-beta.3",
|
|
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",
|