22

Web Assembly

 5 years ago
source link: https://www.tuicool.com/articles/hit/UrQFzaV
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Web Assembly, the what, the why and the how

The what

Web assembly also called Wasm is an efficient, low level byte code for the web, the efficient part means that it’s not only fast to deliver to the client browser but also fast to execute, it’s characterised by being a safe and a portable language meaning that you won’t have to deal with memory overflows and issues like that and the generated machine code can be executed on any platform and adapts to its architecture.

The why

W3C created Wasm for two major reasons, the first one as a complementary solution to JavaScript especially for applications with heavily CPU/GPU computations (think games, encryption, image or video optimisation and editing etc..), and the second one is to enable developers to write their web apps in other languages.

The how

Wasm is defined as a compilation target meaning that in a normal scenario you would write your program in some other languages (currently supporting C/C++ and Rust) and then compile it to a web assembly executable file.

The generated binary file can be injected to your web application and the browser parsing the file will skip all the steps usually run when parsing JS files and go straight to generating the machine code for the platform you’re using, and this is happening because Wasm is already optimised and has static types informations.

Getting started

To play around with Wasm, I recommend https://webassembly.studio/ which is an awesome web editor allowing devs to experiment with Wasm and write web assembly based projects.

There is also https://mbebenita.github.io/WasmExplorer/ which is basically a tool used to translate C/C++ code to Wasm binary code and even see the linear assembly byte-code generated by the browser (this is basically the human readable intermediary representation for the machine code)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK