vortex
A drop-in replacement for piscina 5.3.2: a Node.js worker thread pool with a lock-free shared-memory core.
Same API, same options, same events. piscina's own test suite runs against it unmodified and passes. MIT OR Apache-2.0.
What it is. vortex runs JavaScript functions on a pool of Node.js worker_threads, with
the public interface of piscina 5.3.2: run(),
close(), destroy(), abort signals, move(), task queues, custom load balancers,
histograms and every option piscina accepts. Underneath, queues, placement, completion and
worker accounting live in one SharedArrayBuffer. Workers take tasks from their own inbox
in shared memory, and small arguments and results (undefined, null, booleans, numbers,
strings up to 240 UTF-8 bytes) never touch a MessagePort.
Status. Version 0.1.0, on npm. The shared-memory core
comes in two implementations of one specification: plain JavaScript (the default) and Rust
(no_std, no allocator, no locks) compiled to WebAssembly, chosen with core: 'rust'.
piscina's suite passes on both, and every benchmark below is reported for both.
Quick start
npm install @avarok/vortex # Node.js 20 or newer
// worker.js
module.exports = ({ a, b }) => a + b;
// main.mjs
import Piscina from '@avarok/vortex';
const pool = new Piscina({ filename: new URL('./worker.js', import.meta.url).href });
console.log(await pool.run({ a: 4, b: 6 })); // 10
await pool.close();
CommonJS works the same way: const Piscina = require('@avarok/vortex'). The named
exports are piscina's: Piscina, move, isWorkerThread, workerData, FixedQueue,
ArrayTaskQueue and the symbols.
Migrating from piscina
Change the import. Nothing else.
- const Piscina = require('piscina');
+ const Piscina = require('@avarok/vortex');
- import { Piscina } from 'piscina';
+ import { Piscina } from '@avarok/vortex';
- piscina options are unchanged. Same names, same defaults, same validation and the same error messages; worker files written for piscina run as they are.
spin(vortex only, defaulttrue): an idle worker spins briefly, adaptively and at most 50 µs, before it sleeps.spin: falseturns that off.core(vortex only, default'js'):'rust'runs the pool on the Rust/wasm core instead. Both implement the same memory layout and protocol (docs/design/10-core-spec.md); a differential test holds them to byte-identical results. On the measured cells the Rust core was as fast or faster, by up to 2× at 8 threads (below).- Known differences are listed, every one, in docs/COMPAT.md. The
two most likely to matter:
maxThreadsis capped at 2047, and at most 4096 tasks are in flight at once (the default balancer never reaches that limit unlessmaxThreads × concurrentTasksPerWorkerexceeds it).
Benchmarks
Measured on one machine: Apple M4 Pro (12 cores, 8P + 4E), 48 GB, macOS, Node.js
v22.23.3, both vortex cores (build ce, commit e90e5f4). Fixed iterations (echo 200,000 tasks, obj 100,000,
spin50 40,000, 1,024 in flight; latency 20,000 sequential round trips). Every cell runs in
a fresh process, with a warmup and five repetitions, all implementations interleaved within
each repetition. A load gate (1-minute load under 15, no CI job on the machine) was checked
before and after every cell; none was discarded. Pools run at minThreads = maxThreads = threads, library defaults otherwise.
Median of five repetitions. Bold marks the best in that row.
| workload | threads | vortex, JS core (default) | vortex, Rust/wasm core | piscina 5.3.2 | tinypool 2.2.0 | workerpool 10.0.3 |
|---|---|---|---|---|---|---|
| echo, tasks/s | 4 | 622k | 686k | 131k | 207k | 182k |
| echo, tasks/s | 8 | 274k | 559k | 107k | 182k | 163k |
| obj, tasks/s | 4 | 405k | 428k | 123k | 202k | 176k |
| obj, tasks/s | 8 | 227k | 355k | 102k | 181k | 155k |
| spin50, tasks/s (ideal 80k) | 4 | 74.9k | 74.7k | 55.7k | 56.1k | 55.8k |
| spin50, tasks/s (ideal 160k) | 8 | 143k | 142k | 80.9k | 97.6k | 89.7k |
| latency p50, µs | 4 | 4.4 | 4.4 | 11.7 | 10.3 | 9.5 |
| latency p50, µs | 8 | 4.5 | 4.5 | 13.7 | 10.6 | 9.5 |
| latency p99, µs | 4 | 12.1 | 10.7 | 19.9 | 17.2 | 17.4 |
| latency p99, µs | 8 | 13.2 | 12.1 | 24.3 | 17.6 | 18.0 |
echo returns its argument, obj returns a small object (it travels through the port),
spin50 busy-waits 50 µs. On these workloads both vortex cores had higher throughput than
the other three pools in every cell (1.3–5.2× piscina, 1.25–3.3× tinypool) and the lowest
p50 and p99 latency. The JS core is the slower of the two at 8 threads (echo 274k
against 559k, obj 227k against 355k) and its 8-thread throughput varies between runs
(echo 270k–381k over five repetitions); the cause has not been investigated yet.
Raw data, one line per cell with CPU, Node version and load: bench/results/cores-t4.jsonl
and cores-t8.jsonl (the run also measured every
intermediate build). Method, fix series and step-by-step analysis:
docs/design/09-bench.md. One script draws the charts and the
table from the jsonl (bench/charts.json); CI fails if they differ:
node scripts/bench-charts.mjs bench/charts.json assets
How the four compare
| vortex | piscina | tinypool | workerpool | |
|---|---|---|---|---|
| API | piscina 5.3.2's, tested by piscina's suite | its own | piscina-like, not identical | its own |
| Version measured | 0.1.0 (pre-release) | 5.3.2 | 2.2.0 | 10.0.3 |
| Licence | MIT OR Apache-2.0 | MIT | MIT | Apache-2.0 |
| Task transport | shared-memory slots for small values, postMessage otherwise |
postMessage |
postMessage |
postMessage |
What this does not prove
- No "fastest" claim beyond these cells. One machine (Apple M4 Pro), one OS (macOS), one
Node.js version (22.23.3), four workloads, 4 and 8 threads, library defaults. Not
measured: Linux or x86, Node.js 20 or 24, payloads over 240 bytes beyond
obj, transfer lists, abortable tasks, custom balancers,concurrentTasksPerWorker > 1,atomics: 'async', many pools in one process, long mixed workloads. - Most of the latest gain is one shim change, not the core. Step by step: the Rust
core's call-cost work took echo at 4 threads from 395k to 432k; waking the main thread
by port message alone (no
Atomics.waitAsync) took it to 686k and p99 from 28 to 11 µs. - Builds before commit 9a39534 can hang: a lost wake-up in the main thread's completion
wait (both cores; 2 of 40 cold
objcells). Fixed; modelled inloom_main_wait.rs. - Open defect: a terminated worker can survive
terminate(). With source maps enabled (--enable-source-maps, or thetsxloader piscina's test suite runs under) and a task that runseval, a worker running awhile (true)task occasionally keeps running afterterminate(), sodestroy()never settles: 3 of 100 cold runs of one piscina test; 0 of 100 without flags or withouteval; 0 for piscina. Cause unknown: docs/design/08-node-shim.md §8.8.
Compatibility
piscina 5.3.2's test suite is vendored unmodified in compat/piscina-5.3.2/ (pinned by
sha256) and runs against vortex and against piscina itself through the same harness. On
Node.js 22.23.3 (macOS, arm64): 154 tests, 149 pass, 5 skipped, 0 fail, for both. The
skips are the suite's own conditions (nice tests that run only on Linux or Windows, Node.js 24-only dispose
tests, a test for machines with at most 8 CPUs). The same counts hold on Node.js 20.20.2
and 25.1.0. The Node.js 24-only tests have not been run against vortex yet.
npm run build && node scripts/compat.mjs vortex 4 # vortex
node scripts/compat.mjs piscina 4 # piscina, same harness
How it works
js/src/core: the core interface (CoreApi) and the JS core, the default.crates/vortex-core: the Rust core.no_std, no allocator, no locks, no I/O. A worker can die at any instruction and the core recovers its tasks. Checked with loom models, property tests and native stress tests incrates/vortex-core-tests.crates/vortex-wasm: the core compiled forwasm32-unknown-unknownwith shared memory, behind a flat FFI. No wasm-bindgen.js/src: the TypeScript shim that is piscina's interface: options, queues, balancers, abort, histograms, async resources, close and destroy.
Design notes, proofs and measurements: docs/DESIGN.md.
Questions people ask
Is vortex a drop-in replacement for piscina?
For piscina 5.3.2, yes: change the import. piscina's own suite passes unmodified; the differences we know of are in docs/COMPAT.md.
Is it faster than piscina?
On the measured cells (Apple M4 Pro, Node.js 22.23.3, 4 and 8 threads), throughput was 1.3–5.2× piscina's, and p50 and p99 latency were the lowest of the pools measured. Nothing else has been measured.
Which core should I use?
Both pass the same suite. core: 'rust' was as fast or
faster on every measured cell, up to 2× at 8 threads.
Does it need Rust at runtime?
No. The core ships as a .wasm file inside dist/. Rust
is needed only to build from source.
How do I build it from source?
npm ci && npm run build in a clone. That needs the
Rust toolchain pinned in rust-toolchain.toml, with the wasm32-unknown-unknown target.
Which Node.js versions?
20 and newer (engines). The piscina suite has been run on
20.20.2, 22.23.3 and 25.1.0.
Contributing and security
See CONTRIBUTING.md and the code of conduct. Report vulnerabilities privately, as described in SECURITY.md.
vortex is a project of Avarok Cybersecurity.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option. Material from piscina and Node.js is credited in THIRD-PARTY-NOTICES.md; see also NOTICE.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.