3 ms·
A little known annoying detail of web workers is that passing large data to them via postMessage is incredibly slow. The browser has to convert your javascript
by richardanaya 5y ago
A little known annoying detail of web workers is that passing large data to them via postMessage is incredibly slow. The browser has to convert your javascript object into some sort of internal binary format and it slows down the thread that's doing the sending.
- reginaldo 5y agoDepends on the type of large data, but since 2011 there's "Transferable" [1], where objects like ArrayBuffer, MessagePort, and ImageBitmap can be transferred with a low overhead [2]. Now, if you're passing large arbitrary object graphs, you're out of luck. [1] https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast https://developers.google.com/web/updates/2011/12/Transferab... [2] https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage https://developer.mozilla.org/en-US/docs/Web/API/Worker/post...
- MuffinFlavored 5y agoAny libraries that make this nicer/easier to do instead of rewriting the same thing over and over?
- The_rationalist 5y agohttps://github.com/Bnaya/objectbuffer https://github.com/Bnaya/objectbuffer and comlink