WebAssembly (or WASM) is a new type of code that can run on modern web browsers. It is a low-level language like assembly with a compact binary format. It can run with similar performance to C/C++ and Rust languages that are compiled so that they can run on the web browsers. WebAssembly is also designed to run together with JavaScript.
Web development using WebAssembly is an alternative way to run code written in multiple languages on the web and accelerate some processing tasks such as graphics, video processing, or complex math calculations.
No need to learn how to write WASM code, because you can load WebAssembly modules into the web and enable WebAssembly functionalities to be used through JavaScript. This is to enhance performance, introduce new features, and make functions easy to use and convenient for web developers.
Objectives of WebAssembly
- Efficient and Fast: WebAssembly can be executed on a wide range of platforms at near-native speed by taking advantage of hardware capabilities.
- Readable and debuggable: WebAssembly is a low-level assembly language designed to be a human-readable text format. This allows developers to write, check, and debug their own code.
- Keep secure: WebAssembly is in a safe, sandboxed execution environment. It enforces the same permission and origin policies of the browser as other web codes.
- Don’t break the web: WebAssembly is designed to be completely compatible with other web technologies and maintain backward compatibility.
Main concepts of WebAssembly
- Module : Represents the WebAssembly binary compiled by the browser into executable machine code. A module is stateless; thus, it is like a blob. It can be shared specifically between windows and workers (via postMessage()). The module declares imports and exports like ES modules.
- Memory : A resizable ArrayBuffer of bytes read and written by WebAssembly’s low-level memory access instructions.
- Table : A resizable Array of References cannot be stored as raw bytes in memory (for safety and portability reasons).
- Instance : It is a module matched with all states used at runtime, including memory, tables, and a set of imported values. An instance is like an ES module loaded into a specific global group with a specific set of imported values.
Differences between traditional web development and WebAssembly
- Programming Languages: In traditional web development, JavaScript is primarily used as a programming language for client-side scripts, HTML is used to structure content, and CSS is used to style and layout web pages. On the other hand, codes of WebAssembly can be written in many languages such as C, C++, Rust and compiled to a binary format. Therefore, it enables high-performance code to be run on the browser together with JavaScript.
- Execution Model: In traditional web development, the browser reads and processes text in JavaScript to display on the web browser, but when developing by WebAssembly, the browser reads the entire module as a binary file and processes it.
- Performance: JavaScript is an Interpreted Language (code is read and processed line by line by a translator to translate and process each instruction in real time) while WebAssembly is designed for high-performance processing. It can process code at near-machine language speed.
- Codebase And Libraries: Traditional web development relies on JavaScript libraries and frameworks with a large network of tools available for building web applications. WebAssembly is a new technology with a smaller network compared to those of JavaScript. However, WebAssembly can use the JavaScript libraries and frameworks through coordination and data binding. For these reasons, developers can reuse their codes and integrate WebAssembly modules into their applications.
- Portability: WebAssembly is compatible with various platforms, meaning that the same WebAssembly module can run on different operating systems and web browsers without modifying the codes.
- Application Scope: Traditional web development is suitable for a wide range of web applications from simple to complex web applications. On the other hand, WebAssembly focuses on performance, and it is suitable for applications that require complex computation, such as gaming, media processing, streaming data, and scientific modeling.
Conclusion
WebAssembly is relatively new and unstable. It is still in a design state today, although it has been released since 2015. This is unlike JavaScript which has been around for a long time, and it is quite stable. However, when the WebAssembly is officially released to the public and has more communities in the future, it will be likely to get attention again for intensive use, such as gaming, computing tasks, and graphics-intensive tasks.
Source:
https://developer.mozilla.org/en-US/docs/WebAssembly/Concepts