Closed novemberborn closed 3 years ago
@dnlup maybe you'd be interested in this one? 😉
What strategy should we implement?
Ah yes. Let's throw an error, like we already do when there is a version mismatch:
https://github.com/avajs/ava/blob/0e5cc7dc2b1512d0abe9bfba57b26888eedea0cf/lib/worker/plugin.js#L86
I'll try to work on it
Awesome!
In terms of shared memory, I was thinking of a chaining API like .sharing(buffer1, buffer2).publish({buffer1, buffer2})
. That would work for .broadcast()
as well.
When transferring memory that isn't sensible when broadcasting, so there could be a .transferring(buffer1, buffer2).publish({buffer1, buffer2})
API.
See:
https://github.com/avajs/ava/blob/0e5cc7dc2b1512d0abe9bfba57b26888eedea0cf/plugin.d.ts#L15
https://github.com/avajs/ava/blob/0e5cc7dc2b1512d0abe9bfba57b26888eedea0cf/plugin.d.ts#L35
https://github.com/avajs/ava/blob/0e5cc7dc2b1512d0abe9bfba57b26888eedea0cf/plugin.d.ts#L41
But perhaps that could be follow-up work.
Awesome!
In terms of shared memory, I was thinking of a chaining API like
.sharing(buffer1, buffer2).publish({buffer1, buffer2})
. That would work for.broadcast()
as well.When transferring memory that isn't sensible when broadcasting, so there could be a
.transferring(buffer1, buffer2).publish({buffer1, buffer2})
API.See:
https://github.com/avajs/ava/blob/0e5cc7dc2b1512d0abe9bfba57b26888eedea0cf/plugin.d.ts#L15
https://github.com/avajs/ava/blob/0e5cc7dc2b1512d0abe9bfba57b26888eedea0cf/plugin.d.ts#L35
https://github.com/avajs/ava/blob/0e5cc7dc2b1512d0abe9bfba57b26888eedea0cf/plugin.d.ts#L41
But perhaps that could be follow-up work.
I'll see if I can put something together. I have to document myself a bit about shared memory 😉
Is the sharing/transferring memory operation stateful? Like, once called, should the memory be stored in the object (so only a single call to sharing
/transfering
is necessary) or has it to be coupled just with the single publish
operation?
Regular array buffers can only be transferred once. Shared array buffers can be shared multiple times.
I might be overthinking it, we're really exposing https://nodejs.org/api/worker_threads.html#worker_threads_port_postmessage_value_transferlist but it'd be easier to communicate the restrictions through a chaining based API.
Now that https://github.com/avajs/ava/pull/2690 has landed, we should update our shared worker implementation to only work when worker threads are used. It'll be faster, since the shared worker can talk directly to the test worker; we can transfer array buffers and even use shared memory.