I actually think there's a
third way of "using JS to write Wasm", which is to have a JS library which has instructions to emit "hand-written" Wasm bytecode.
Example of such a library:
https://github.com/iden3/wasmbuilderThat's actually what I was thinking about when picking this option!
Think of the following situation:
- You're a JS developer, and want to write a client / library mainly with JS
- You want to use Wasm only for some narrow, performance-critical parts
In this case, you may not want to use something like Rust, because that adds tooling overhead, makes the Wasm bytecode bigger & makes it harder to hand-optimize the Wasm. On the other hand, you might not want to directly write the Wasm in raw WAT, because that has crappy DX.
In this situation, having a JS library is a viable way to make the writing of raw Wasm somewhat more efficient.
Example of this pattern being used in the wild: https://github.com/iden3/wasmcurves/blob/master/src/bls12381...
That's actually what I was thinking about when picking this option! Think of the following situation:
- You're a JS developer, and want to write a client / library mainly with JS
- You want to use Wasm only for some narrow, performance-critical parts
In this case, you may not want to use something like Rust, because that adds tooling overhead, makes the Wasm bytecode bigger & makes it harder to hand-optimize the Wasm. On the other hand, you might not want to directly write the Wasm in raw WAT, because that has crappy DX.
In this situation, having a JS library is a viable way to make the writing of raw Wasm somewhat more efficient. Example of this pattern being used in the wild: https://github.com/iden3/wasmcurves/blob/master/src/bls12381...