Frontend
September 18, 2026
1 views
2 min read

When It Makes Sense To “Block” The Main Thread

Curated by Patrick
Source: Smashing Magazine
When It Makes Sense To “Block” The Main Thread
Tech Daily Byte Analysis

While building Fastary, Ayomipo observed a consistent 2‑3 second delay when offloading canvas work to an Offscreen Document, despite the conventional wisdom that background workers keep the UI responsive. The delay stemmed from the Structured Clone Algorithm (SCA) that Chrome invokes on every postMessage call: it deep‑copies the 8 MB payload, a synchronous O(n) operation that stalls the main thread longer than the actual image processing would have. Because Chrome extension messaging (chrome.runtime.sendMessage) forces JSON‑style serialization, Transferable objects—such as ArrayBuffers that can be handed off in under 7 ms for a 32 MB buffer—were unavailable, leaving the extension to suffer the cost of cloning.

The episode underscores a broader shift in front‑end performance engineering: developers are increasingly measuring the total cost of a task, not just its CPU time. As browsers expose richer multi‑process APIs (Web Workers, Service Workers, Offscreen Documents), the temptation to default to background threads grows, yet the hidden latency of data marshalling can erode gains, especially in extension contexts where messaging constraints limit the use of Transferables. This nuance aligns with recent Chrome DevTools updates that surface serialization time in performance panels, nudging teams to profile end‑to‑end latency rather than assume workers are always faster.

Looking ahead, the Fastary case suggests that toolchains and browser APIs must make zero‑copy hand‑offs more accessible across all contexts, or provide clearer diagnostics for when cloning becomes a bottleneck. Until then, developers should benchmark both the processing and the transfer path, especially for media‑heavy workloads, and consider hybrid approaches—such as processing small frames on the main thread while reserving workers for truly massive datasets. Monitoring upcoming Chrome releases that may relax extension messaging to accept Transferable objects will be critical for maintaining performant, native‑like experiences.

Key Takeaways

In Fastary, the SCA’s synchronous copy of an 8 MB image added more delay than the canvas computation itself.

Chrome extension messaging currently blocks the use of Transferable objects, forcing costly JSON‑style serialization.

Performance decisions must weigh both computation time and data‑transfer overhead, especially for media‑intensive tasks.

Future Chrome updates that enable zero‑copy transfers in extensions could restore the advantage of off‑thread processing.

About the Source

This analysis is based on reporting by Smashing Magazine. Here is a short excerpt for context:

The common rule of thumb is to never “block” the browser’s main thread when running JavaScript tasks. But is this a hard rule? Victor Ayomipo describes a use case he encountered involving a screenshot extension where he made an exception to the rule and decided that blocking the main thread was absolutely the right thing to do.
Read the original at Smashing Magazine

More in Frontend