What is a WebAssembly (Wasm) module?
Asked Answered
I

2

8

Was reading the MDN docs regarding Wasm. They used the term WASM module quite a few times. Their definition was the following:

A WebAssembly.Module object contains stateless WebAssembly code that has already been compiled by the browser and can be efficiently shared with Workers, and instantiated multiple times. To instantiate the module, call the secondary overload of WebAssembly.instantiate().

I couldn't quite understand the meaning of this. Is a web assembly module simply a Wasm file or is it something else?

India answered 5/10, 2018 at 20:28 Comment(1)
I don't know WASM, but that description sounds like it's an object in memory, not a file. i.e. a reference to the JIT-compiled machine code, rather than the wasm source text.Afb
B
6

WebAssembly is a low-level form of code that can be executed within modern browsers. In order to execute this code the browser must compile it, although because it is low-level, this compilation is relatively fast and simple when compared to JavaScript.

The WebAssembly APIs separate the compilation step from the instantiation and execution step. Therefore, the WebAssembly module is a compiled version of your WebAssembly code (which is the wasm file you refer to) that is ready for instantiation and execution.

Barrera answered 6/10, 2018 at 15:33 Comment(0)
J
9

What is Web Assembly?

Web Assembly(Wasm) is a way of taking code written in programming languages other than JavaScript and running that code in the browser.

It is generated by the compiler with a binary format which allows us to execute any language code on the browser

How does it work?

Despite its name, WebAssembly is not quite an assembly language because it’s not meant for any specific machine. It’s for the browsers, and when you’re delivering code to be executed in the browser, you don’t know what kinds of machines will your code be running on.

What WebAssembly enables you to do is to take things like C, C++ or Rust code and compile it into what is called a WebAssembly module. You can load that into your web application and call it from JavaScript.

Wasm programs are deployed in two stages.

  1. Wasm module is generated from the source code (any language of your choice other than JavaScript)
  2. Once the Wasm module is built, it can be run anywhere with a few lines of JavaScript glue:

It’s not a replacement for JavaScript, it works alongside JavaScript.

Here is a great article to go more in details.

Jimmyjimsonweed answered 12/5, 2020 at 23:19 Comment(0)
B
6

WebAssembly is a low-level form of code that can be executed within modern browsers. In order to execute this code the browser must compile it, although because it is low-level, this compilation is relatively fast and simple when compared to JavaScript.

The WebAssembly APIs separate the compilation step from the instantiation and execution step. Therefore, the WebAssembly module is a compiled version of your WebAssembly code (which is the wasm file you refer to) that is ready for instantiation and execution.

Barrera answered 6/10, 2018 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.