What is the difference in accessing the canvas?

The following approach https://rustwasm.github.io/wasm-bindgen/examples/2d-canvas.html access the canvas through Rust, this approach however https://rustwasm.github.io/wasm-bindgen/examples/julia.html uses JS.

What is the actual difference between these approaches? F.e.: is the Rust more efficient?

Canvas is accessed from JS in any case, since Wasm doesn't have direct access to any browser API. The only difference is whether we call this functions via FFI (i.e. they are passed from JS to Wasm themselves), or we use some glue code (which can, as in the second example, prepare everything in JS and then call to Wasm only for actual computation).

In some cases, the second approach will be more effecient, since there's less jumps from JS to Wasm and again to JS. In most cases, however, the difference will probably be only in ergonomics, since AFAIK JIT-compiled JS and AOT-compiled Wasm can be bridged almost seemlessly.

1 Like

Okay, thank you for this response! It's all still quite hard to map

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.