vortex

6. Where piscina 5.3.2 spends per-task time (profile, phase 2a)

@avarok/vortex 0.1.0 · Updated

These are CPU-profile shares, not benchmark results. Nothing here is a throughput claim. Tools: tools/profile-piscina/run.cjs (drives empty tasks) and tools/profile-piscina/analyze.cjs (self-time aggregation of a .cpuprofile).

Setup: piscina 5.3.2 from the npm tarball, Node 20.20.2, Apple M3 Max (16 cores), minThreads = maxThreads = 2, empty handler (n) => n, node --cpu-prof (one profile per thread). Machine 1-minute load 7.5–8.4 during the runs (shared machine; shares are robust to that, absolute times are not).

Reproduce:

node --cpu-prof --cpu-prof-dir=<out> tools/profile-piscina/run.cjs <piscina-dir> 200000 2 1
node --cpu-prof --cpu-prof-dir=<out> tools/profile-piscina/run.cjs <piscina-dir> 400000 2 64
node tools/profile-piscina/analyze.cjs <out>/<file>.cpuprofile 20

6.1 One task in flight (latency regime), 200 000 tasks

Thread Busy Largest self-time items
main 39 % (61 % idle) postTask 11.6 %, get interface 5.5 %, (program) 6.5 %, GC 4.0 %, postMessage 1.5 %
worker 1 21 % (79 % in Atomics.wait) postMessage 9.4 %, receiveMessageOnPort 5.2 %, onMessage 2.2 %, getHandler 2.1 %
worker 2 0 % never given a task: the balancer always picks the first idle worker

Reading: a round trip is about 14 µs of wall time on this machine, of which the two threads together are busy for well under half; the rest is wake-up latency in both directions (futex wake of the worker, libuv/port wake of the main thread). This is the regime techniques T3 (spin-then-park) and the completion-wake choice in T2 address.

6.2 64 tasks in flight (throughput regime), 400 000 tasks

Thread Busy Largest self-time items
main 80 % (20 % idle) postTask 21.9 %, get interface 8.9 %, (program) 6.0 %, GC 5.5 %, postMessage 3.8 %, receiveMessageOnPort 4.6 %, microtask machinery ~5 %, async_hooks 1.6 %
workers 1, 2 15 % each (85 % in Atomics.wait) postMessage ~4 %, receiveMessageOnPort ~4–6 %, onMessage ~3 %, getHandler ~1.7 %

Line-level ticks inside postTask (main thread): 528 of ~660 samples are on the Atomics.notify line, 121 on port.postMessage. piscina issues a futex wake syscall for every task, whether or not the worker is waiting.

Reading:

  1. The main thread is the bottleneck; workers starve. With concurrentTasksPerWorker = 1 each worker finishes, posts, and then waits until the main thread has processed the result and dispatched the next task: a strict ping-pong through the busiest thread.
  2. Unconditional Atomics.notify is the single largest item (~17 % of main-thread time).
  3. Per-task worker-list materialisation (get interface, plus the spread/map that calls it) is ~9 %.
  4. Serialisation proper (postMessage + receiveMessageOnPort native) is a smaller share than the scheduling overhead around it.

6.3 Consequences for the design (applied to chapters 2 and 3)