loading...

Reduce overhead for data serialization between Wasm & JS (Help!)

wenheli profile image WenheLI ・1 min read

I am trying to export Rust gif library to js runtime by using wasm to get a high-performance gif encoding/decoding library (repo). However, when running benchmarking, I found huge overhead for data serialization in the process (15ms for decoding & 300ms+ for data serialization).

Any ideas on how to address it, folks?
Help and discussion are appreciated 👍

Discussion

markdown guide
 

something I noticed when I opened the repo, here github.com/WenheLI/wasm-gif/blob/6...

you are doing an allocation (calling .to_vec()) which is not necessary here since you iterate over it again so why you make a separate copy of every frame on that hot loop?

 

yep, that's definitely a redundant allocation!
However, based on the performance I measured, I found the major overhead exists in JsValue::from_serde(&gif).unwrap() where this process took up to 90% execution time of the whole function.
Thanks anyway!
BTW, I am wondering if there is a way to pass an object reference to wasm runtime or can wasm return a stream object?