WebAssembly (Wasm) is a low-level assembly-like language that defines a binary format and corresponding text for a stack-based virtual machine.
WebAssembly is an emerging standard as the biggest advancement to the Web Platform which includes people from the W3C Community group like Apple, Google, Microsoft, Mozilla etc. Firefox, Chrome, latest versions of Edge and Safari browsers support the wasm format on Windows, MacOS, Linux and Android, Firefox being the first one.
- A new language: It defines an AST (Abstract Syntax Tree), a binary format which can be authorized and debugged in a readable text format.
- A Compile Target: Provide binary support across the entire web platform to all the languages.
- Efficient: Binary format allows it to be small in size and hence reduced loading time.
- Fast: It executes at native speed with the help of common hardware capabilities provided with platforms.
- Open and debuggable: The textual format allows to debug, test, experiment, optimize, learn, teach, and write programs by hand.
- Part of the open web platform: It doesn’t support any version and is backward compatible.
Use of WebAssembly
It can be used for high-performance web-apps and many existing productivity apps like-
- Computer-aided design
- Video and image editing
- Scientific Visualization
- Social networks
- Word processing
- Face detection
- VR and augmented reality
- It runs the code on the web at a native speed written in multiple languages.
- With a compressed and efficient AST, it provides cost-effective parsing.
- Loading large data can take 20 – 30 seconds in ASM.js which is too long but with a compressed AST encoding, it takes a couple of seconds.
- It eliminates the need for browser plug-ins to support graphics-heavy and online games.
- C/C++ applications can be kept on the web without rewriting.
- It allows importing compute-intensive applications and scientific simulation to the web platform.
- It also supports non-web applications such as the mobile apps, Internet of Things and JVM.
How does WebAssembly work?
Values: Basically global variables with one of the available types – integers and floats.
Memory: The memory object makes it possible to achieve manual memory management.
The instance is successfully instantiated with the compiled code and imports. It can now be used to call methods.
WebAssembly: An object namespace for all WebAssembly related functionality.
WebAssembly.Module(): A WebAssembly.Module object contains compiled code of WebAssembly which is stateless and can be efficiently shared.
WebAssembly.instantiateStreaming(): The WebAssembly.instantiateStreaming() function compiles and instantiates the WebAssembly code. returning.
WebAssembly.Table(): A WebAssembly.Table object is a resizable typed array of values that are accessed by an instance like function references.
WebAssembly.CompileError(): Creates a new WebAssembly CompileError object.
WebAssembly.LinkError(): Creates a new WebAssembly LinkError object.
WebAssembly.RuntimeError(): Creates a new WebAssembly RuntimeError object.
The web is constantly evolving, and with the introduction of WebAssembly now developer can build apps that run on browsers at native speed. Existing code in C, C++ etc can now run on the browser without being re-written. This could be the turning point for web. So, are you ready to embrace it?