Web Assembly – the coding modernization

Web Assembly – the coding modernization

  • Post category:Blog / Web
  • Post comments:0 Comments
  • Reading time:6 mins read

What is Web Assembly ?

Web Assembly is a new type of code that can be run in modern web browsers, it is a low-level assembly like language with a compact binary format that runs with near-native performance and provides languages such as C/C++ and Rust with a compilation target so that they can run on the web. It is also designed to run alongside JavaScript, allowing both to work together. Web Assembly, developed by the W3C, is in the words of its creators a “compilation target.” Developers don’t write Web Assembly directly; they write in the language of their choice, which is then compiled into Web Assembly bytecode. The bytecode is then run on the client, typically in a web browser, where it’s translated into native machine code and executed at high speed.

Is Web Assembly better than Java Script in terms of speed ?

Web Assembly code is meant to be faster to load, parse, and execute than JavaScript. When Web Assembly is used by a web browser, there is still the overhead of downloading the WASM module and setting it up, but all other things being equal Web Assembly runs faster. Web Assembly also provides a sandboxed execution model, based on the same security models that exist for JavaScript now. Right now, running Web Assembly in web browsers is the most common use case, but Web Assembly is intended to be more than a web-based solution. Eventually, as the Web Assembly spec shapes up and more features land in it, it may become useful in mobile apps, desktop apps, servers, and other execution environments.

What values does Web Assembly bring in to the web platform ?

Web Assembly has huge implications for the web platform, it provides a way to run code written in multiple languages on the web at near native speed, with client apps running on the web that previously couldn’t have done so. Web Assembly is designed to complement and run alongside JavaScript using the Web Assembly JavaScript APIs, you can load Web Assembly modules into a JavaScript app and share functionality between the two. This allows you to take advantage of Web Assembly’s performance and power and JavaScript’s expressiveness and flexibility in the same apps, even if you don’t know how to write Web Assembly code.

What are the advantages of using Web Assembly ?

  • An improvement to JavaScript : Implement your performance critical stuff in wasm and import it like a standard JavaScript module.
  • A new language : Web Assembly code defines an AST (Abstract Syntax Tree) represented in a binary format. You can author and debug in a text format so it’s readable.
  • A browser improvement : Browsers will understand the binary format, which means we’ll be able to compile binary bundles that compress smaller than the text JavaScript we use today. Smaller payloads mean faster delivery. Depending on compile-time optimization opportunities, Web Assembly bundles may run faster than JavaScript, too!
  • A Compile Target : A way for other languages to get first-class binary support across the entire web platform stack.

What are the features of Web Assembly ?

Web Assembly defines an Abstract Syntax Tree (AST) that gets stored in a binary format. Binary is great because it means we can create smaller app bundles. You’re probably wondering how we’ll debug a binary language format. Among other things, it will be easy to express things like threads and SIMD, a fancy word that means you can line up multiple chunks of data next to each other and invoke a single instruction to operate on all of them at the same time. It stands for Single Instruction, Multiple Data.

That means fat, parallel processing pipelines for your real time video stream effects processor. If you have your finger on the pulse, you’ve probably already heard of doing this in JS, but I’ve always found it a bit awkward to try to do low level stuff like this using JavaScript’s existing type system. This is one of those cases where you’ll probably want to forget about the object system, the garbage collector, and all the fancy dynamic stuff. Just line up some raw bits in little rows and crunch through them as fast as possible.

How does Web Assembly cater to the compiling complexities of the code ?

Web Assembly adds things that most JS developers would agree we don’t need in JavaScript. We may still get those things, but not because we need them for JavaScript code. We’ll get them to support compiling from other languages which use them. Web Assembly gives us an alternative compile target, one specifically designed for that purpose. It will be easier now to port code that relies heavily on features like shared memory threads. I’d bet that the process of writing a compiler for Web Assembly will be somewhat less complicated than writing a compiler for JavaScript, simply because there’s a better mapping from the source language features to the target AST.

Why not use the JVM ?

We’ve tried to put the JVM in browsers before via plugins. It didn’t work out so well. JavaScript already has a VM. Another VM means a second set of API hooks to give the VM access to the DOM, networking, sensors, input devices, etc… That’s not free. How will VM processes like garbage collection get along competing for the same resources? That may be harder than it sounds.

Initially, Web Assembly will run on an asm.js poly fill, meaning it can take advantage of the existing JavaScript VM foundations. The design will evolve from that base, so there is a smoother browser integration path than alternative VMs could provide.

Doesn’t this mean other languages will take over ? Won’t this cause fragmentation ?

JavaScript has always had strong competition on the server side and in embedded programming for small hardware and robots, but in spite of many existing, viable alternatives with established package ecosystems and lots of trained developers, Node is still taking over startup and enterprise web servers at a torrential pace.

Leave a Reply