2 ms·
You can bypass the serialisation cost by using the transferList for ArrayBuffer instances, which is used by typed arrays i.e. Int32Array, Float64Array etc. i.e
by cjdell 10y ago
You can bypass the serialisation cost by using the transferList for ArrayBuffer instances, which is used by typed arrays i.e. Int32Array, Float64Array etc.
i.e. self.postMessage(myTypedArray, [myTypedArray.buffer])
I used this approach to generated geometry within a web worker for a WebGL project. Only downside is the web worker that initialised the array will lose ownership of the buffer and will have to create a new one to pass more information.
https://developer.mozilla.org/en/docs/Web/API/Worker/postMessage https://developer.mozilla.org/en/docs/Web/API/Worker/postMes...
- Touche 10y agoYeah, it's really only useful for game dev and other math heavy use-cases. In normal JavaScript, which could also benefit from threads, you use Objects and Arrays, which can't be transferred.