Skip to the content ForoHackers
Log inJoin

WebAssembly: start here

WebAssembly
#3091 · · Quote · Report

WebAssembly is a compact binary instruction format for a portable, sandboxed virtual machine. Languages such as C, C++ and Rust compile to it, and browsers run it next to JavaScript at near-native speed. Outside the browser, it is used as a safe, portable way to run plugins and services. It is a compilation target more than a language you write by hand.

Key concepts

  • Stack machine and modules: a module has typed functions with simple instructions over a value stack.
  • Linear memory: one resizable array of bytes that the module addresses; the host decides what else it can reach.
  • Sandboxing: a module can only do what its imports allow, with no direct access to the system.
  • Imports and exports: functions passed in from the host and exposed back to it.
  • Host interface: in a browser, JavaScript glues modules to the page; outside, a system interface standardises file and clock access.
  • Text and binary formats: a readable text form for study and a compact binary for delivery.

Vocabulary

  • Module: the compiled unit of WebAssembly, validated before it runs.
  • Runtime: the engine that executes modules, in a browser or standalone.
  • WASI: the system interface for running WebAssembly outside browsers.
  • Toolchain: a compiler and linker that target WebAssembly from another language.

What to study, in order

  1. Read a small module in its text format and run it with a standalone runtime.
  2. Compile a C or Rust function to WebAssembly and call it from JavaScript.
  3. Pass strings and structures through linear memory, and see why it is manual.
  4. Run a module outside the browser and limit what it may access.
  5. Compare performance with plain JavaScript on a computation-heavy task.
  6. Read the specification's validation and execution sections.

Related tags

#rust #javascript #browsers #runtimes

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply