Browser & Frontend Runtime
Workers: multiple-choice review
Six questions that cut across the whole unit. Each one mirrors an architectural call you make under real load — which primitive fits, what it costs, and the failure mode it cannot solve — not a definition to recite.
Confirm you can pick the right worker primitive for a job, reason about its data-transfer cost, and recognise the lifecycle and isolation traps the three primitives cannot solve on their own.
A teammate moves a slow React list re-render into a web worker to fix scroll jank, and nothing improves. Why, and what actually fixes it?
You postMessage a 40 MB Float32Array to a worker and the sending thread still freezes for ~40 ms before the worker even starts. Best fix?
You deploy a new service worker, reload, and still get old behaviour with no error. The new worker installed fine. What is happening?
A multithreaded-WASM module silently runs single-threaded in production. typeof SharedArrayBuffer is 'undefined' and crossOriginIsolated is false; COOP: same-origin is set but COEP is not. What is the exact fix and its cost?
A button triggers a 400 ms image job. Users click rapidly; the tab spawns a new worker per click, climbs to 400 MB, and gets killed on mobile. What is the right architecture?
A service worker intercepts navigation and serves the app shell cache-first. You ship a shell bug; some users hit the broken cached shell on every reload with no recovery button. What is the architectural defence?
The through-line of the unit is one decision tree: pick the primitive by job — web worker for off-main-thread compute, service worker for the network proxy, SharedArrayBuffer for shared memory — then pay the right transport cost (clone for small data, transfer for large binary, SAB for concurrent access behind COOP+COEP). Around that, three traps recur: a worker cannot touch the DOM (so DOM mutation never offloads), a service worker waits before activating and is hard to recover when it breaks navigation, and pools need backpressure or they leak. None of the primitives fixes a main-thread DOM bottleneck — that work stays where the DOM lives.