Skip to content

Instantly share code, notes, and snippets.

@ChristophP
Last active July 14, 2022 14:15
Show Gist options
  • Save ChristophP/479d042ad1a81ee13f09d2d35e28bbbe to your computer and use it in GitHub Desktop.
Save ChristophP/479d042ad1a81ee13f09d2d35e28bbbe to your computer and use it in GitHub Desktop.
Stuff I've learned about WASM and WASI

WASM and WASI Notes

Web Assembly can make use of OS capabilities with the Web Assembly System Interface. It allows calls to OS functionality like clock, fs, network etc.

Spec

  • WASM is the fourth W3C web standard next to HTML, CSS and JS
  • WASI is an additional spec that standardizes how Web Assembly can do more than just run in a sandboxed environment but interact with system resources.

Ecosystem

  • Runtimes supporting WASI:
    • wasmtime
    • wasmer
    • wasm3
  • wasmer offers a package manager for WASM modules called WAPM
  • WASI needs to be implemented for each language/platform (browsers use a memory FS)
  • WASI is bound to the WASM module as imports during instanciation
  • Many languages already compile to WASM: C/C++ via Emscripten, Rust, many more to come
  • WASM runs in JS engines by default, Other languages can use bindings for a WASM runtime like WASMER
  • edge support: for example in cloudflare workers

WASM Benefits

  • More lightweight than containers
  • Highly portable (just need a WASM runtime)
  • Functions as a compile target for nearly every language

Why does the majority not use WASM?

  • No killer feature for majoriy classic web use cases, extra effort not justified since JS does the job well enough already
  • high performance:
    • web
      • TensorFlow JS
      • Google Earth
      • Unity (Game Engine)
      • Auto CAD
    • devops: lightweight deployments with WASM and Docker
  • edge computing: very fast startup (example: Cloud flare workers
  • using a different language that doesn't run in the browser: Python in the browser (PyScript
  • security: sandboxed enviroment, fine-grained control over what the WASM program can see (env vars, folder & files, args, sockets, etc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment