WebAssembly — Next Generation Web Platform.

Omkesh B. Kendre
4 min readJun 14, 2023

--

WebAssembly — Wasm

WebAssembly refers to assembly language on web browsers. It is a portable binary code format that runs on web browsers and supports Rust, C, C++, and C#, among other programming languages.

There has only ever been one programming language that can be used natively in a web browser for the past 20+ years. WebAssembly is supported by modern web browsers and is intended to work in conjunction with javascript.

Major Concepts

Instance: A Module along with every piece of runtime state it requires, such as a Memory, Table, and collection of imported values. An instance is comparable to an ES module that has been loaded with a specific set of imports into a specific global.

Table: a resizable typed array of references that cannot otherwise be kept in Memory as raw bytes, such as references to functions (for safety and portability reasons).

Module: represents a WebAssembly binary that the browser has converted into machine code that can be executed. Because a Module is stateless, it can be explicitly shared across windows and workers (through postMessage()), much like a Blob. In the same way as an ES module does, a module specifies imports and exports.

Memory: The linear array of bytes read and written by the low-level memory access instructions used by WebAssembly is stored in a resizable ArrayBuffer.

Advantages of WebAssembly

  • close to native performance — Although results do vary by the runtime, WebAssembly is almost always quicker than JavaScript, especially for compute-intensive tasks, and averages 1.30 to 1.50 times slower than native code.
  • Security — Security was a priority when developing WebAssembly. The program’s objective is to safeguard consumers from potential web security threats while enabling programmers to create secure apps. By separating module execution in a sandboxed environment and implementing well-known browser security regulations, WebAssembly offers a secure application experience.
  • Debugging is simple — Although WebAssembly is a low-level assembly language, it does feature a human-readable text format that enables code to be written, examined, and manually debugged (the standard for which is currently being finalized).
  • Open-source — It is open source and aspires to support every language on any operating system; however, in reality, all of the most widely used languages already have support to varying degrees.
  • quicker, more effective, and portable — Code written in WebAssembly is designed to execute more quickly by utilizing the hardware available on various systems.

JavaScript API

Use the WebAssembly JavaScript APIs if you want to share modules between WebAssembly and JavaScript.

  1. WebAssembly.compile() — A WebAssembly.Module object is created by compiling WebAssembly binary code using the WebAssembly.compile() function.
  2. WebAssembly.CompileError() — An problem during WebAssembly decoding or validation is indicated by the WebAssembly.CompileError() object.
  3. WebAssembly.compileStreaming() — Direct compilation of a WebAssembly.Module from a streamed underlying source is accomplished via the WebAssembly.compileStreaming() function.
  4. WebAssembly.Exception() — A runtime exception thrown from WebAssembly to JavaScript or from JavaScript to a WebAssembly exception handler is represented by the WebAssembly.Exception() object.
  5. WebAssembly.Global() — A global variable instance that can be imported or exported between two or more WebAssembly.Module instances are represented by a WebAssembly.Global() object. Multiple modules can be linked dynamically thanks to this.
  6. WebAssembly.Instance() — A stateful, executable instance of a Module is a WebAssembly.Instance() object. All of the Exported WebAssembly functions that enable JavaScript to call WebAssembly code are included in instance objects.
  7. WebAssembly.instantiate() — You can compile and instantiate WebAssembly code using WebAssembly.instantiate() API.
  8. WebAssembly.instantiateStreaming() — The primary API for compiling and launching WebAssembly code returns a Module along with the initial instance of that Module. This function is called WebAssembly.instantiateStreaming().
  9. WebAssembly.LinkError() — An problem during module instantiation is indicated by the WebAssembly.LinkError() object ( In addition to the start-up function for traps ).
  10. WebAssembly.Memory() — A WebAssembly.Memory() object is an ArrayBuffer that may be resized and contains the actual bytes of memory that an Instance has accessed.
  11. WebAssembly.Module() —Stateless WebAssembly code that has already been built by the browser is contained in a WebAssembly.Module() object, which can be efficiently shared among Workers and instantiated numerous times.
  12. WebAssembly.RuntimeError() — Every time WebAssembly defines a trap, the WebAssembly.RuntimeError() object is the error type that is raised.
  13. WebAssembly.Table() — An Instance can access a WebAssembly.Table() object, which is a resizable typed array of opaque data like function references.
  14. WebAssembly.Tag() — An exception that can be thrown to or from WebAssembly code is defined by the WebAssembly.Tag() object.
  15. WebAssembly.validate() — A typed array of WebAssembly binary code is validated by the WebAssembly.validate() function.

“A game-changer like WebAssembly doesn’t show all his cards at once.” Stay tuned for more on WebAssembly.

--

--