structured clone algorithm
The standard JavaScript algorithm for deep-copying values between threads and into storage, which handles Maps, Sets, Dates, typed arrays and circular references.
In more detail
It is richer than JSON but cannot copy functions or DOM nodes. The global structuredClone() function exposes it for making deep copies in your own code. Copying large objects takes time and memory on both sides, so large binary data is better transferred than copied.
Related terms
- postMessage() — The method used to send data between a page and a worker, or between windows, delivered as a message event on the other side.
- transferable object — An object, such as an ArrayBuffer, ImageBitmap or MessagePort, whose memory can be moved to another thread instead of copied.
- serialization — Turning an in-memory object into bytes, such as JSON text, that can be sent or stored, and parsing it back again.
- circular reference — When objects refer to each other in a loop, such as a parent pointing to a child that points back to the parent.
- MessageChannel — A pair of connected ports for sending messages between threads: what you post on one port arrives as a message event on the other.
Taught in
- Web Workers: Off-Thread Computation And Structured Clone — Frontend Architecture & Web Platform
- Worker Threads: worker_threads & SharedArrayBuffer — Node.js Internals & Backend Services