vortex

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.

@avarok/vortex 0.1.0 · Updated

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';

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.

Throughput in tasks per second, median of five, in the order vortex JS core, vortex Rust core, piscina, tinypool, workerpool. echo at 4 threads: 622k, 686k, 131k, 207k, 182k; at 8 threads: 274k, 559k, 107k, 182k, 163k. obj at 4 threads: 405k, 428k, 123k, 202k, 176k; at 8 threads: 227k, 355k, 102k, 181k, 155k. spin50 at 4 threads: 74.9k, 74.7k, 55.7k, 56.1k, 55.8k; at 8 threads: 143k, 142k, 80.9k, 97.6k, 89.7k. Sequential round-trip latency in microseconds, p50 / p99, in the order vortex JS core, vortex Rust core, piscina, tinypool, workerpool. 4 threads: 4.4 / 12.1, 4.4 / 10.7, 11.7 / 19.9, 10.3 / 17.2, 9.5 / 17.4. 8 threads: 4.5 / 13.2, 4.5 / 12.1, 13.7 / 24.3, 10.6 / 17.6, 9.5 / 18.0.

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

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

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

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.