4

According to the Calls between JavaScript and WebAssembly are finally fast 🎉 article:

calls between JS and WebAssembly are faster than non-inlined JS to JS function calls.

At the same time, as the WebAssembly Concepts article states:

By itself, WebAssembly cannot currently directly access the DOM; it can only call JavaScript, passing in integer and floating point primitive data types. Thus, to access any Web API, WebAssembly needs to call out to JavaScript, which then makes the Web API call.

That means in most cases to access DOM from WASM two function calls are needed: first - to call a bridging JS function from WASM, second - to call an actual DOM-manipulating function from the bridging JS function.

Do I understand it correctly that until these functions are not inlined somehow (so there is only one function call instead of two), there should be a super small performance downgrade while manipulating DOM from WASM?

Are there any actual benchmarks showing the difference in the performance between direct JS and JS-from-WASM DOM manipulations?

Is it reasonable to use WASM for the entire web application (not only for computation-intensive parts) if it's mostly about only DOM manipulations?

3
  • Quote from above link: "The JavaScript glue code is not as simple as you might imagine." Aside from speed, one also needs to decide if WASM is worth the extra overhead and complexity.
    – Yogi
    Commented Jul 19, 2022 at 19:02
  • Yup. But let's pretend that we live in a kind of ideal world - so there is some smart compiler or other processor which generates all required glue functions for us, and we call DOM manipulations from our source code in the way pretty similar to JS. If my assumptions are correct, glue functions can be the reason of at most x2 performance downgrade for each DOM function call. Also, there is a doubt that compiled WASM bytecode is going to have smaller size than similar minified JS texts downloaded by browser.
    – Andrei K.
    Commented Jul 19, 2022 at 19:24
  • 1
    Here is the answer on app sizes: stackoverflow.com/a/62289399/3945245. And here is the possible answer regarding the performance: stackoverflow.com/a/59728411/3945245
    – Andrei K.
    Commented Jul 20, 2022 at 13:30

0