vortex: design
vortex is a worker thread pool whose core (queues, scheduling, worker accounting,
backpressure, timing) is Rust compiled to wasm32-unknown-unknown with shared memory,
and whose public interface is a drop-in replacement for
piscina 5.3.2.
Status: phases 2a–2c done (core, Node.js shim; piscina 5.3.2's suite passes unmodified). Behaviour differences: COMPAT.md.
Chapters
- The interface vortex matches: pinned version, every export, option, method, event, property, static, worker convention and error string, with defaults and validation.
- Architecture: one shared
WebAssembly.Memory, the Rust core (no_std, lock-free, no allocator, survives a worker killed at any instruction), the JS shim and why each JS piece cannot be Rust, task lifecycle, scheduling modes, the three-lane codec, browsers. - Where the speed comes from: piscina's per-task costs read from its source, the techniques that remove them, their risks, and honest limits.
- Proof plan: piscina's own test suite run unmodified against vortex, the benchmark harness and its rules, Rust concurrency tests (loom, death injection).
- Phased plan and owner decisions.
- Where piscina spends per-task time: CPU-profile shares (not benchmarks) behind the scheduling decisions.
- The Rust core as built: protocols, why SeqCst fences, histograms, verification record with negative controls, gaps for phase 2c.
- The Node.js shim as built: push placement through per-worker inboxes (and why it replaced pull for now), the per-task path, worker waits, worker records, verification record with negative controls.
Decisions in one place
- Reference: piscina
v5.3.2(commit6c7e546); 6.x is a later additive layer. - Shared state lives in one shared wasm memory; the main thread is the only allocator; workers never allocate and the core never takes a lock.
- The balancer (default or custom) places every task, as in piscina; the worker receives it through its own shared-memory inbox. Pull from the shared ring with prefetch stays in the core as a phase 4 ablation (chapter 8.1).
- The main thread never blocks: one
Atomics.waitAsyncdrains completions in batches. - Idle workers spin for an adaptive, capped budget, then park with
memory.atomic.wait32. - Values move through a fast shared-memory lane when exactness against
structuredCloneis proven, otherwise throughpostMessage, which is also the only lane for transfers andSharedArrayBuffer. - Every performance claim is measured with machine load beside the number.