# Benchmarks (V8, JSC & Rust)

> 15-run process-isolated V8 (Node 26) and JavaScriptCore (Bun 1.3) benchmarks, Rolldown tree-shaken bundle budgets, and Rust 1.100 release measurements.

* **Baseline:** Real `@tanstack/store@0.11.3` (`tanstack-atom` direct `createAtom`/`batch` ceiling & `tanstack-store` idiomatic `createStore`/`Store`)
* **Hardware:** Apple M1 (`darwin/arm64`)
* **Engines Tested:**
  * **V8:** Node.js `v26.14.0` (V8 `14.6.202.34-node.58`), `node --expose-gc` -> [ts/bench/results_v8.json](https://github.com/kjmin-dev/zwire/blob/main/ts/bench/results_v8.json)
  * **JavaScriptCore (JSC):** Bun `1.3.11`, `bun:jsc` `heapStats()` -> [ts/bench/results_jsc.json](https://github.com/kjmin-dev/zwire/blob/main/ts/bench/results_jsc.json)
* **Methodology:** 4-mode subprocess isolation per target (`--worker-correctness`, `--worker-memory`, `--worker-bench`, `--worker-bundles`), >=200ms JIT warmup, **15 measured runs** reporting `median`, `p95`, and `IQR`, popped-frame heap sampling (preventing V8 Ignition loop-register retention bias), and virtual `Rolldown` (`rolldown@1.4.0`, `treeshake: true, format: 'esm', minify: true, comments: false`) + `zlib.gzipSync(..., { level: 9 })`.

---

## 1. Correctness & GC Regression Gates (15 Checks, Identical on V8 & JSC)

| Gate | Description | `@zwire/core` | `tanstack-atom` | `tanstack-store` |
| :--- | :--- | :---: | :---: | :---: |
| G1 | Basic & Diamond Glitch-Free | **PASS** | PASS | PASS |
| G2 | Multi-level Early Cutoff | **PASS** | PASS | PASS |
| G3 | Dynamic Dependency Switching | **PASS** | PASS | PASS |
| G4 | `atom.set(undefined)` Safety | **PASS** | **FAIL** *(ignored)* | **FAIL** *(ignored)* |
| G5 | Flush Exception Queue Recovery | **PASS** | **FAIL** *(poisoned)* | **FAIL** *(poisoned)* |
| G6 | SSR Multi-Scope Isolation | **PASS** | **FAIL** *(global leak)* | **FAIL** *(global leak)* |
| G7 | ObjectStore 100-Field Fan-out | **PASS** *(1 eval)* | PASS *(100 evals)* | PASS *(100 evals)* |
| G8 | Optimistic Rebase + STM Verify | **PASS** | N/A | N/A |
| G9 | 5,000-Row Collection Accuracy | **PASS** | PASS | PASS |
| G10 | 3-Hop Computed Unsub GC (`WeakRef`) | **PASS** | PASS | PASS |
| G11 | Unwatched Computed GC (`WeakRef`) | **PASS** *(0 leaked subs)* | **FAIL** *(0/64, 65 leaks)* | **FAIL** *(0/64, 65 leaks)* |
| G12 | Nested `C1->a->C2(a)->a` Edge Dedup | **PASS** *(2 / 21 links)* | **FAIL** *(3 / 40 links)* | **FAIL** *(3 / 40 links)* |
| G13 | ObjectStore `setKey()`+`get()` Immutability | **PASS** | PASS | PASS |
| G14 | Optics `subscribe(focus(...))` | **PASS** | N/A | N/A |
| G15 | Sparse 5/1,000 Lazy Key Allocation | **PASS** *(<= 5 atoms)* | N/A | N/A |

---

## 2. Full Performance & Memory Matrix (15-Run Medians, Lower = Better)

### 2.1 Node.js v26.14.0 (V8)

| Scenario | `@zwire/core` | `tanstack-atom` | `tanstack-store` | `@zwire/core` vs `tanstack-atom` / `Store` |
| :--- | ---: | ---: | ---: | :--- |
| **B1** Single R/W (`ns/op`) | **42.71** | 49.32 | 45.86 | **1.15x** / **1.07x** |
| **B2a** 1k-field `set()` rot (`µs/op`) | **81.57** | 168.78 | 166.78 | **2.07x** / **2.04x** *(1 vs 1k evals)* |
| **B2b** 1k-field `setKey()` rot (`ns/op`) | **590.7** | 164,726 | 166,102 | **279x** / **281x** |
| **B2b-16** `setKey()` + `get()` 16:1 (`ns/op`) | **691.2** | 169,035 | 177,825 | **245x** / **257x** |
| **B2b-1** `setKey()` + `get()` 1:1 (`ns/op`) | **2,002.9** | 167,133 | 164,078 | **83.4x** / **81.9x** |
| **B2c-map** 1k `AtomMap` rot (`ns/op`) | **59.71** | 88.62 | 96.3 | **1.48x** / **1.61x** |
| **B2c-arr** 1k Decomposed Array (`ns/op`) | **25.85** | 74.58 | 78.2 | **2.89x** / **3.03x** |
| **B3a** Diamond-50 Propagate (`µs/op`) | 4.58 | **4.16** | 4.53 | 0.91x / 0.99x |
| **B3b** Diamond-50 Cutoff (`ns/op`) | **1,249.0** | 1,512.9 | 1,601.5 | **1.21x** / **1.28x** |
| **B3c** Unwatched + 50k Unrel (`ns/op`) | **27.16** *(0 leaks)* | 28.75 *(leaks)* | 40.65 *(leaks)* | **1.06x** / **1.50x** |
| **B4** Dynamic Dep Flip (`ns/op`) | **136.78** | 151.15 | 173.34 | **1.11x** / **1.27x** |
| **B5** 10k Sub Churn (`ns/op`) | **44.09** | 107.61 | 122.25 | **2.44x** / **2.77x** |
| **B6** Batch 1k Writes (`µs/batch`) | **10.67** | 31.34 | 40.55 | **2.94x** / **3.80x** |
| **B7** Optimistic Rebase (`µs/cycle`) | **0.396** | N/A | N/A | Unique capability *(2.53M cycles/s)* |
| **B8** SSR 500 Scopes (`ms`) | **2.019** | N/A | N/A | Unique capability *(4.04 µs/scope)* |
| **B9a** 50k Col Initial Build (`ms` / `KB`) | **0.506 ms** / 406 KB | 2.01 ms / **395 KB** | 2.01 ms / 395 KB | **3.97x faster build** *(Lazy Sorted-Frontier + Dense-ID)* |
| **B9b** 50k Rand Row Update (`µs/upd`) | **0.038** | 2,030.6 | 2,059.2 | **53,438x** / **54,191x** |
| **B10** Popped-Frame Heap (`B/pair`) | **369.1** | 1,242.0 | 1,578.3 | **3.36x** / **4.28x** less RAM |

### 2.2 Bun 1.3.11 (JavaScriptCore / Safari Engine)

| Scenario | `@zwire/core` | `tanstack-atom` | `tanstack-store` | `@zwire/core` vs `tanstack-atom` / `Store` |
| :--- | ---: | ---: | ---: | :--- |
| **B1** Single R/W (`ns/op`) | **33.12** | 54.80 | 60.29 | **1.65x** / **1.82x** |
| **B2a** 1k-field `set()` rot (`µs/op`) | **69.66** | 122.51 | 118.95 | **1.76x** / **1.71x** *(1 vs 1k evals)* |
| **B2b** 1k-field `setKey()` rot (`ns/op`) | **150.5** | 115,824 | 123,412 | **769x** / **820x** |
| **B2b-16** `setKey()` + `get()` 16:1 (`ns/op`) | **2,527.8** | 118,096 | 126,028 | **46.7x** / **49.9x** |
| **B2b-1** `setKey()` + `get()` 1:1 (`ns/op`) | **35,147** | 117,042 | 126,396 | **3.33x** / **3.60x** |
| **B2c-map** 1k `AtomMap` rot (`ns/op`) | **39.39** | 70.03 | 95.5 | **1.78x** / **2.42x** |
| **B2c-arr** 1k Decomposed Array (`ns/op`) | **24.24** | 55.76 | 76.8 | **2.30x** / **3.17x** |
| **B3a** Diamond-50 Propagate (`µs/op`) | **3.82** | 4.02 | 4.09 | **1.05x** / **1.07x** |
| **B3b** Diamond-50 Cutoff (`ns/op`) | **1,170.1** | 1,502.5 | 1,521.9 | **1.28x** / **1.30x** |
| **B3c** Unwatched + 50k Unrel (`ns/op`) | **17.49** *(0 leaks)* | 43.02 *(leaks)* | 67.61 *(leaks)* | **2.46x** / **3.87x** |
| **B4** Dynamic Dep Flip (`ns/op`) | **100.81** | 161.14 | 194.65 | **1.60x** / **1.93x** |
| **B5** 10k Sub Churn (`ns/op`) | **35.58** | 132.15 | 245.42 | **3.71x** / **6.90x** |
| **B6** Batch 1k Writes (`µs/batch`) | **10.08** | 22.44 | 40.79 | **2.23x** / **4.05x** |
| **B7** Optimistic Rebase (`µs/cycle`) | **0.335** | N/A | N/A | Unique capability *(2.99M cycles/s)* |
| **B8** SSR 500 Scopes (`ms`) | **2.268** | N/A | N/A | Unique capability *(4.54 µs/scope)* |
| **B9a** 50k Col Initial Build (`ms` / `KB`) | **0.421 ms** / 407 KB | 1.79 ms / **394 KB** | 1.82 ms / 395 KB | **4.25x faster build** *(Lazy Sorted-Frontier + Dense-ID)* |
| **B9b** 50k Rand Row Update (`µs/upd`) | **0.042** | 1,866.0 | 1,998.4 | **44,428x** / **47,580x** |
| **B10** Popped-Frame Heap (`B/pair`) | **368** | 1,120 | 1,648 | **3.04x** / **4.48x** less RAM |

---

## 3. Tree-Shaken Bundle Matrix (`Rolldown --minify` + `gzip` Level 9)

Run `node ./bench/run_precision_bench.ts --check-bundles` or the same command with Bun from `ts/`. Both runtimes enforce the following gzip budgets. The named collection probe covers the original factory. The full collection probe includes range queries and incremental transactional edits.

Adapter subpaths (`@zwire/<fw>/tx`, `/collections`, `/resource`, `/protocol`) import the core subpath they mirror, so their delta is measured over core plus that subpath.

| Entrypoint | Minified (B) | Gzip (B) | Core + subpath (B gz) | Delta (B gz) | Budget (B gz) |
| :--- | ---: | ---: | ---: | ---: | ---: |
| `@tanstack/store { createAtom, batch }` | 3,718 | 1,484 | — | — | — |
| `@tanstack/store { createStore, createAtom, batch }` | 4,270 | 1,631 | — | — | — |
| `@tanstack/store (export *)` | 6,885 | 2,344 | — | — | — |
| `@zwire/core { atom, computed, subscribe, batch }` | 15,863 | 5,322 | — | — | 5,600 standalone |
| `@zwire/core (export *)` | 18,723 | 6,263 | — | — | 6,400 standalone |
| `@zwire/core/tx` | 25,144 | 8,293 | 9,333 | +3,070 | 4,500 delta |
| `@zwire/core/collections { createCollection }` | 28,293 | 9,132 | 10,143 | +3,880 | 4,500 delta |
| `@zwire/core/collections (export *)` | 33,760 | 10,669 | 11,686 | +5,423 | 5,500 delta |
| `@zwire/core/protocol { hydratable, dehydrate, hydrate }` | 17,501 | 5,900 | 6,927 | +664 | 1,500 delta |
| `@zwire/core/protocol (export *)` | 22,783 | 7,805 | 8,816 | +2,553 | 3,500 delta |
| `@zwire/core/store { createObjectStore }` | 22,289 | 7,364 | 8,390 | +2,127 | 3,500 delta |
| `@zwire/core/store { createDeepStore }` | 22,522 | 7,322 | 8,308 | +2,045 | 3,500 delta |
| `@zwire/core/optics` | 19,996 | 6,693 | 7,727 | +1,464 | 2,500 delta |
| `@zwire/react` | 18,861 | 6,309 | 7,255 | +992 | 1,500 delta |
| `@zwire/vue` | 17,538 | 5,892 | 6,881 | +618 | 1,500 delta |
| `@zwire/solid` | 17,030 | 5,712 | 6,707 | +444 | 1,500 delta |
| `@zwire/svelte` | 17,394 | 5,826 | 6,812 | +549 | 1,500 delta |
| `@zwire/react/tx` | 28,440 | 9,512 | 10,488 | +1,155 | 1,300 delta |
| `@zwire/vue/tx` | 28,570 | 9,530 | 10,523 | +1,190 | 1,300 delta |
| `@zwire/solid/tx` | 28,218 | 9,421 | 10,407 | +1,074 | 1,300 delta |
| `@zwire/svelte/tx` | 28,245 | 9,436 | 10,413 | +1,080 | 1,300 delta |
| `@zwire/react/collections` | 16,094 | 5,421 | 11,883 | +197 | 500 delta |
| `@zwire/vue/collections` | 16,538 | 5,570 | 12,029 | +343 | 500 delta |
| `@zwire/solid/collections` | 16,294 | 5,464 | 11,921 | +235 | 500 delta |
| `@zwire/svelte/collections` | 16,498 | 5,559 | 12,026 | +340 | 500 delta |
| `@zwire/react/resource` | 16,502 | 5,540 | 7,488 | +283 | 600 delta |
| `@zwire/vue/resource` | 16,700 | 5,614 | 7,560 | +355 | 600 delta |
| `@zwire/solid/resource` | 16,803 | 5,627 | 7,562 | +357 | 600 delta |
| `@zwire/svelte/resource` | 16,571 | 5,557 | 7,503 | +298 | 600 delta |
| `@zwire/react/protocol` | 16,900 | 5,649 | 8,985 | +169 | 500 delta |
| `@zwire/vue/protocol` | 17,154 | 5,803 | 9,116 | +300 | 500 delta |
| `@zwire/solid/protocol` | 16,963 | 5,672 | 9,014 | +198 | 500 delta |
| `@zwire/svelte/protocol` | 16,732 | 5,639 | 8,957 | +141 | 500 delta |

---

## 4. Honest Trade-Offs & Rust Release Benchmarks

1. **Bundle Size Floor vs `@tanstack/store`:** `@zwire/core` (`5.96 KB` gz full / `5.20 KB` gz minimal) is larger than full `@tanstack/store` (`2.29 KB` gz) and minimal `{ createAtom, batch }` (`1.45 KB` gz). That footprint buys zero-global SSR scopes with `dispose()`, monomorphic core fast paths, 2-phase split `effect()`, `watch()`, optional microtask `scheduler` + `flush()`, lexical `Owner` tree (`createRoot`/`onCleanup`/`catchError`), `NotReady` sentinel, `shallowEqual`, `WeakRef`-verified GC-safe unwatched computeds, cycle detection, zero-try exception-safe flush recovery, `undefined`-safe equality, nested duplicate-link prevention, TC39 `onWatched`/`onUnwatched` hooks with activation rollback, and 5 extension slots.
2. **V8 Deep Diamond Full Propagation (`B3a`):** `@zwire/core` sweeps JSC (`3.82 µs` vs `4.02–4.09 µs`) and V8 `B1`/`B3b`, while on V8 `B3a` is `4.58 µs` vs `4.16–4.53 µs` due to per-evaluation cycle-stamped edge dedup (`_m`) that fixes Gate 12 (where `@tanstack/store` fails with duplicate edges).
3. **JSC Dictionary Spread on 1:1 Whole-Object Snapshots (`B2b-1`):** Calling whole-object `store.get()` after every single `setKey()` on a 1,000-key dictionary object incurs JSC's `{ ...obj }` spread cost (`35.1 µs` vs `2.00 µs` on V8, though still `3.3x–3.6x` faster than TanStack). All 4 UI adapters route `useSelector` through duck-typed `FieldSubscribable` (`subscribeField`) to avoid whole-object snapshots completely.

### Rust 1.100 Release Benchmarks (`engine_bench` & `collection_churn`)

Run `cargo bench --bench engine_bench` and `cargo bench -p zwire-collections --bench collection_churn` from `rust/`:

| Benchmark | Workload | Latency (Apple M1, Rust 1.100 release) |
| :--- | :--- | ---: |
| **B1** | `Scope` atom set + watched computed | **`80.6 ns/op`** |
| **B2a** | `Scope` 50-layer diamond propagate | **`8,341.4 ns/op`** |
| **B2b** | `Scope` 50-layer diamond early cutoff | **`2,273.4 ns/op`** |
| **B3** | `SyncScope` 4-thread concurrent R/W (`RwLock`) | **`623.9 ns/op`** |
| **B4** | `OptimisticLayer` rebase + revert + settle | **`1,003.7 ns/op`** |
| **B5** | `ReactiveCollection` 50k upsert + Top-50 (re-entrant safe) | **`600.4 ns/op`** |
| **B5b** | `PureReactiveCollection` (`KeyedCollection` `BTreeSet`, 50k + Top-50) | **`171.9 ns/op`** |
| **B5c** | `SyncPureReactiveCollection` (`RwLock<KeyedCollection>`, 50k 4-thread + Top-50) | **`535.7 ns/op`** |
| **B6** | `WireValue` JSON parse + serialize | **`661.0 ns/op`** |

In `collection_churn` (200,000 deterministic rank changes across 100k / 1M rows, 5-round medians): `Collection` chunks took `80 ms` / `223 ms`, `Collection::with_sort_key` took `68 ms` / `157 ms`, `KeyedCollection` (`BTreeSet<(S, K, u32)>`) took **`59 ms` / `158 ms`** (min `56 ms` / `140 ms`), vs raw `BTreeMap + BTreeSet` `57 ms` / `113 ms`.
