Hacker News new | ask | show | jobs
by gmitscha 1456 days ago
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/wasmbuilder

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...

1 comments

That's definitely interesting, but seems a bit less convenient compared to, for example, writing some TypeScript (compiled to Wasm) and importing that into the JS like we already can with AssemblyScript. AS recently gained the ability to output native ES Modules (containing Wasm and exposing the exported APIs) to import into native ES Modules in plain JS (with type definitions).