🎄Web Assembly - Introduction🌟
What is Web Assembly?
Web Assembly (or WASM) is a new standard that allows you to run compiled code in the browser. It's a low level language that is designed to be fast and portable.
You can compile C, C++, Rust, Go, Java, Python, Ruby, PHP, Haskell, C#, and many other languages to WASM.
Why Web Assembly?
- Run performance critical code in the browser (e.g. video encoding, image processing, 3D rendering, etc.)
- Reuse existing code (e.g. you can compile C++ code to WASM and run it in the browser)
- Write code in your favorite language (e.g. you can write C++ code and compile it to WASM and run it in the browser)
Examples of libraries using Web Assembly
This website is using multiple libraries which are compiled to WASM:
- viz-js - Graphviz in your browser
- SQL.js - SQLite compited to WASM to run in the browser
- JQ-web - JQ as a library in the browser
- Pyodide - Python interpreter in the browser
These are examples of existing libraries/tools that were compiled to WASM to run in the browser.
How to use Web Assembly?
Let's say you have an image processing code written in C++ that uses OpenCV library.
Now you want to run that in the browser.
Each language has their own way to compile to WASM. For c++ everybody is using emscripten.
Here is an example article describing how to compile c++ into wasm. https://developer.mozilla.org/en-US/docs/WebAssembly/C_to_Wasm