Anyone explored using WebAssembly for NIFs?


I was wondering if anyone has explored using WebAssembly for NIFs?

As well as being very hip and trendy (always important :wink:) wasm seems to have some nice properties that fit the BEAM well.

  • Due to its sandboxed nature we can be sure that it can’t crash the VM.
  • Capabilities are injected so we can be sure what native code can do. No risk of a malicious package sending HTTP requests to collect your data.
  • It is intended to compile quickly so would reduce build times for packages that would have otherwise used C
  • A wasm binary contains all its dependencies, making build requirements simpler than packages that would otherwise be using C.

I’d love to hear about any experiments anyone has!



I’ve seen a couple of these recently, but I am not sure this is what you were thinking of?

These are still NIFs as we know them, just relying on the rust compiler to do the heavy lifting. I guess a future step could be to teach OTP directly to speak WASM, so you could just pull in an OTP library with a wasm binary and it would Just Work?


I agree, I think there could be significant gains in exploring this possibility.

I just don’t know if things like syscalls (network mostly) could be addressed with WASM given the current state of WASI. But I’m sure not all NIF´s depend on it to work.


The user experience I was imagining was very similar to that of NIFs today, only the programmer would provide a .wasm file rather than a .so file. This would require quite a lot of tooling, but it was exciting to think about what that would be like.