gloo icon indicating copy to clipboard operation
gloo copied to clipboard

transferables in gloo-worker

Open jneem opened this issue 3 years ago • 3 comments

gloo-worker uses post_message to send serialized messages between workers. For some messages, it might be better to use post_message_with_transfer to send partially serialized messages while avoiding expensive copies. For example, if I had a struct like

struct Foo {
  bar: i32,
  baz: f64,
  giant_array: web_sys::ArrayBuffer,
}

then I'd like to send this between workers by serializing the first two fields and transferring giant_array. Is this a use-case that gloo-worker is interested in supporting? The implementation I have in mind would involve custom Serialize-Deserialize-like traits and a derive macro...

(edit: I didn't mean to add the "bug" label, sorry, but it looks like I can't remove it)

jneem avatar Aug 02 '22 17:08 jneem

Has any work been done to address this limitation? Or is there a workaround available somewhere else? This is something I really need right now.

BuggStream avatar Mar 20 '23 20:03 BuggStream

I've been just doing my workers "by hand" instead of using gloo-worker. I'm "serializing" my structs to javascript Arrays by hand and using post_message_with_transfer. It's a bit painful, but it's doable if you only have a couple different kinds of structs to send.

jneem avatar Mar 20 '23 23:03 jneem

I'm working on doing this "by hand" myself, and I found this trunk example to be instrumental in doing so.

isosphere avatar Apr 07 '24 20:04 isosphere