In JS I have a Window.requestAnimationFrame() loop which gives certain parameters to a Rust function for Rust to read and use every 13ms. I don't fully grasp how invoking a Rust function through Wasm works and so I was wondering if this a good way to do it?
As an alternative I was thinking of putting a loop in Rust which runs every 13ms, which reads the data from wasm memory directly. But I am not sure how to achieve that and if it's worth it, since just giving a Rust function those values as parameters in JS does the job. Maybe there's even another 'better' solution?
I'm not familiar with WASM myself, but if you can set an interval from Rust to read the shared memory directly it will be much more efficient than doing it through a JS API.
Also, I guess if using shared memory and you already know the location and size, you might not even have to pass any parameters at each loop. That might be faster?
But of course.....benchmark if it matters.
I see now I can just call a Rust func (without parameters) from within a JS loop and than use shared mem to read the values, like they do ..... I'll be trying that out too than of course.