DEV Community

WenheLI
WenheLI

Posted on

2 2

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

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 đź‘Ť

Top comments (2)

Collapse
 
shekohex profile image
shekohex •

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?

Collapse
 
wenheli profile image
WenheLI •

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?

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay