Worker object that contains all functions that will be executed in parallel.
Functions should be using CPU-parallelism not IO-parallelism.
Most functions should be synchronous, not asynchronous.
Making them asynchronous does not make a difference to the caller.
The caller must always await because the fucntions will run on the pool.
When passing in Buffer, it is coerced into an Uint8Array. To avoid
confusion, do not pass in Buffer and instead use ArrayBuffer.
If you are passing the underlying ArrayBuffer, ensure that the containing
Buffer is unpooled, or make a slice copy of the underlying ArrayBuffer
with the Buffer.byteOffset and Buffer.byteLength.
Remember the subtyping relationship of buffers:
Buffers < Uint8Array < ArrayBuffer < BufferSource
Only the ArrayBuffer is "transferrable" which means they can be zero-copy
transferred. When transferring a structure that contains ArrayBuffer, you
must pass the array of transferrable objects as the second parameter to
Transfer.
Only transfer things that you don't expect to be using in the sending thread.
Note that Buffer.from(ArrayBuffer) is a zero-copy wrapper.
Worker object that contains all functions that will be executed in parallel. Functions should be using CPU-parallelism not IO-parallelism. Most functions should be synchronous, not asynchronous. Making them asynchronous does not make a difference to the caller. The caller must always await because the fucntions will run on the pool.
When passing in
Buffer
, it is coerced into anUint8Array
. To avoid confusion, do not pass inBuffer
and instead useArrayBuffer
.If you are passing the underlying
ArrayBuffer
, ensure that the containingBuffer
is unpooled, or make a slice copy of the underlyingArrayBuffer
with theBuffer.byteOffset
andBuffer.byteLength
.Remember the subtyping relationship of buffers: Buffers < Uint8Array < ArrayBuffer < BufferSource
Only the
ArrayBuffer
is "transferrable" which means they can be zero-copy transferred. When transferring a structure that containsArrayBuffer
, you must pass the array of transferrable objects as the second parameter toTransfer
.Only transfer things that you don't expect to be using in the sending thread.
Note that
Buffer.from(ArrayBuffer)
is a zero-copy wrapper.