# zwire

> Zero-global, zero-dependency transactional reactive state engine for TypeScript (@zwire/*) and Rust (zwire) with rebaseable optimistic layers, O(1) incremental Top-K collections, and an open wire protocol.

Try `zwire`'s rebaseable optimistic layers live below—reserve funds, trigger a concurrent authoritative server push, and watch active layers automatically rebase before atomic zero-flicker `settle()`:

## Headline Benchmarks (Apple M1)

15-run process-isolated medians in TypeScript ([V8 & JSC benchmarks](/architecture/benchmarks/)) and Rust 1.100 release benches:

| Runtime / Suite | Scenario | Median |
| :--- | :--- | ---: |
| **TS — V8 (`Node 26`) / JSC (`Bun 1.3`)** | **B1** Single atom R/W | **`42.7 ns/op`** / **`33.1 ns/op`** |
| **TS — V8 (`Node 26`)** | **B9a** 50k Collection Initial Build | **`0.51 ms`** / **`406 KB`** |
| **TS — V8 (`Node 26`)** | **B9b** 50k Random Row Update + Top-50 | **`0.038 µs/upd`** |
| **Rust 1.100 (`engine_bench`)** | **B1** `Scope` atom set + watched computed | **`80.6 ns/op`** |
| **Rust 1.100 (`engine_bench`)** | **B3** `SyncScope` 4-thread concurrent R/W | **`624 ns/op`** |
| **Rust 1.100 (`engine_bench`)** | **B5b** `PureReactiveCollection` 50k upsert + Top-50 | **`171.9 ns/op`** |
| **Rust 1.100 (`engine_bench`)** | **B5c** `SyncPureReactiveCollection` 50k 4T + Top-50 | **`535.7 ns/op`** |

## Zero-Global Scoped Engine

Every reactive graph lives inside a `ReactiveScope` (TS) or `Scope` / `SyncScope` (Rust). SSR
mode silences subscriptions per request, and forward-only unwatched links guarantee immediate GC
collection in V8 and JSC.

## Rebaseable Optimistic Layers & STM

Overlapping optimistic intents auto-rebase on concurrent server pushes with zero lost updates,
zero-flicker atomic `settle()`, surgical single-layer `revert()`, and read-set verified STM
`Draft`s.

## Exact Incremental Top-K Collections

2-level Chunked Sorted Block Index (`BLOCK_TARGET = 128`) with deterministic key tie-breaking
and `O(1)` boundary pruning across `@zwire/core/collections` and `#![no_std]`
`zwire-collections`.

## One Open Wire Protocol Across Languages

Canonical RFC-8259 hydration, lossless 64-bit integer transfer, coalesced echo-safe
`SyncBridge`, 4 UI adapters (`@zwire/{react,vue,solid,svelte}`), and optional `zwire-wasm` and
`zwire-serde` bridges.
