Skip to content

Web Workers & Parallelism

Move expensive work off the main thread. Dedicated Workers, transferable objects for zero-copy data, SharedArrayBuffer for true shared memory, OffscreenCanvas for worker-side rendering, and the production patterns that keep your UI at 60fps while crunching data in the background.

1
Why the Main Thread Is the Bottleneck
advanced

The browser's main thread handles JavaScript execution, layout, paint, and user input in a single-threaded event loop. Understanding why this design exists and when it becomes a performance cliff is the foundation for every parallelism strategy.

16 min read
2
Dedicated Workers: Lifecycle & Messaging
advanced

Dedicated Workers give you a separate OS thread for JavaScript execution. Understanding their lifecycle — creation, message passing, error handling, and termination — plus when to use module workers and libraries like Comlink is what separates toy demos from production-grade parallelism.

20 min read
3
Transferable Objects & Zero-Copy
advanced

Structured clone copies data. Transferable objects move ownership without copying a single byte. Understanding which types are transferable, how transfer works at the memory level, and when the zero-copy advantage disappears is critical for high-performance worker communication.

18 min read
4
Cross-Context Communication
advanced

Beyond simple worker.postMessage, the browser provides MessageChannel, BroadcastChannel, SharedWorker, and service worker messaging for complex multi-context architectures. Understanding which channel to use — and when simple postMessage is enough — separates production systems from tutorials.

18 min read
5
Shared Memory & Atomics
advanced

SharedArrayBuffer gives multiple threads access to the same memory. Atomics provides synchronization primitives to prevent data races. Together they enable true shared-memory parallelism in JavaScript — with all the dangers and power that implies.

22 min read
6
OffscreenCanvas & Worker Rendering
advanced

OffscreenCanvas lets you render graphics in a Web Worker — decoupling canvas drawing from the main thread. This keeps the UI responsive while running complex visualizations, image processing, or WebGL rendering at full frame rate.

18 min read
7
Worker Patterns in Production
advanced

Toy demos use one worker for one task. Production systems need pooling, task scheduling, graceful degradation, error recovery, and integration with frameworks like React and Next.js. These are the patterns that separate prototypes from production-grade parallelism.

22 min read