4 ms·
Another nit to pick: "Copying the message: the message is serialized, copied, sent over, and then de-serialized at the other end. The page and worker do not sha
by kipple 9y ago
Another nit to pick: "Copying the message: the message is serialized, copied, sent over, and then de-serialized at the other end. The page and worker do not share the same instance, so the end result is that a duplicate is created on each pass. Most browsers implement this feature by automatically JSON encoding/decoding the value at either end."
This is untrue, modern workers use the structured clone algorithm[0][1], not JSON.stringify() & JSON.parse(). This algorithm has many advantages, such as preserving object references, supporting built-ins like Maps and Sets, and allowing cyclical/recursive structures.
[0] https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...
[1] https://www.w3.org/TR/2012/CR-html5-20121217/infrastructure.html#safe-passing-of-structured-data https://www.w3.org/TR/2012/CR-html5-20121217/infrastructure....