Reference
The channel tax between main thread and workers. Normative base: WHATWG structured data.
worker.postMessage(value);
// value is serialized then deserialized on the other side
// each realm gets its own copy — not the same object
postMessage,
structuredClone(), IndexedDB, etc. (
MDN).
Map/Set,
ArrayBuffer, plain objects, many web types.
DataCloneError.
// Transfer the underlying ArrayBuffer — sender loses it
worker.postMessage(u8, [u8.buffer]);
// after this, u8.byteLength === 0 on the sender (detached)
{ transfer: [...] }).
.buffer is transferable — put the buffer
in the transfer list.
ArrayBuffer,
MessagePort, ImageBitmap,
OffscreenCanvas, streams, …
| Rough payload | Design take |
|---|---|
| ≤ ~10 KiB | Low risk even near frame budget; fine for frequent UI updates |
| ≤ ~100 KiB | Usually OK for interaction budget (~100ms) even on slow devices |
| ≫ 100 KiB or high frequency | Design for patches, chunking, or transfer — don’t clone whole state every tick |
Source framing: Is postMessage slow? — rules of thumb, not laws. Serialize blocks sender; deserialize blocks receiver.
ArrayBuffer ownership.