Shared memory isolation
checking
demo ยท v133
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.
checking
checking
Run the benchmark to see the final head, tail, and slot state.
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.
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;
}
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.