demo ยท v133

SPSC queue throughput

A real single-producer / single-consumer ring buffer in SharedArrayBuffer. One worker writes messages into shared slots while another worker drains them. Run the same queue twice: once with a tight empty spin and once with Atomics.pause() inside the consumer's empty probe.

Shared memory isolation

checking

Atomics.pause

checking

tight empty spin

- msg/s
messages-
empty checks-
checks / msg-
queue full checks-
sourcenot run

empty spin + Atomics.pause

- msg/s
messages-
empty checks-
checks / msg-
pause calls-
sourcenot run

Shared ring state

Run the benchmark to see the final head, tail, and slot state.

What the comparison measures

The paused run should usually show far fewer empty probes per message. Throughput can vary by CPU and scheduler, but the important signal is less useless spinning while the producer is between writes.

real worker queue

The benchmark creates one shared Int32Array layout: head index, tail index, counters, and a power-of-two ring of slots. The producer worker writes sequential messages into empty slots; the consumer worker reads until the producer sets the done flag and the ring is empty. The only difference between the two runs is the consumer's empty path.

if (head === tail) {
  emptyChecks++;
  if (usePause) {
    Atomics.pause(Math.min(64, 1 + (emptyChecks & 31)));
  }
  continue;
}

fallback behavior

If the page is not cross-origin isolated, it cannot construct SharedArrayBuffer. In that case the UI runs an explicitly labeled pattern preview on the main thread instead of pretending to measure a worker queue. On this route the server sends Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp, so local and deployed runs can execute the real worker path.

see also