651.288.7000 info@intertech.com

If you’re reading this there is a good chance that you work in the software development industry in some capacity. Maybe you have heard the term “WebAssembly” over the past few years or simply curious to learn something new. Either way, the goal of this post is to provide an overview of what WebAssembly is, who’s behind it and using it today, and how they (and possibly you) use it to build software applications.

 


 

What Is WebAssembly (WASM)?

“WebAssembly (abbreviated WASM) is a binary instruction format for a stack-based virtual machine. WASM is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications,” per webassembly.org.

The big take away from this is the “compilation target for programming languages.” I highlight this because you may be under the impression that you write WASM code, but in reality you compile your code into WASM binaries. As it states “WASM is a binary instruction file which can run in a stack-based virtual machine.” In other words, a binary file that runs in an abstraction of a computer that acts like real hardware. The goal of WASM is for that abstraction to exist in the browser seamlessly. 

Who Is Behind WebAssembly?

The Web Assembly Working Group, a part of the World Wide Web Consortium (W3C), with contributors from the major players in modern web browsers, including Mozilla, Microsoft, Google and more, is responsible for WebAssembly. In 2019 W3C WebAssembly became the fourth language for the web which allows code to run in the browser, a huge stamp of approval by the people that are building the browsers where your applications will run. This should give you confidence that this is not another fly-by-night technology when considering WebAssembly as a solution for you, your customers, and your business. 

Who’s using it?

At madewithwebassembly.com you can see a list of projects that use WebAssembly. It’s a wide ranging list but here are some of the interesting highlights:

  • Autocad, one of the oldest computer drafting software’s was able to make a web version of their application using WebAssembly.
  • Unity, a gaming engine with a web player made using WebAssembly providing a performant 2D and 3D gaming that would otherwise not be possible.
  • TensorFlow, a JavaScript library used for machine learning modeling. WebAssembly was integrated for better, more performant modeling.
  • GoogleEarth, C/C++ codebases for native applications were ported to the web for performant 3D graphics in the browser.
  • Blazor, one of Microsoft’s newest programming frameworks allows you to write C# code that compiles into WebAssembly that executes client side.

These examples hold a common thread, each projects is dependent on performant code running in the browser using WebAssembly. 

How does it work?

A developer writes code in a WASM supported language (C++, Rust, C# etc..) and then compiles that code into a WASM binary format that is then able to run in the browser. For example, you can compile a C++ library into WASM format and then run functions from the library in a JavaScript web environment. Each supported language compiles to WASM through a unique library or toolchain. For C++, a compiler toolchain called “Emscripten” is used. For Rust, there is a tool called “wasm-pack”. For C# , you build the application with Blazor and Visual Studio (probably only newer versions) handles the rest. 

Why would you use it?

There are a few regular use cases for going to WebAssembly as a solution. 

    • Bottlenecks in your application

Areas in your application that a 50% increase in execution time or more consistent execution time would drastically improve the end users experience. Maybe your application has some backend business logic and you want to eliminate the server usage and the time it takes to communicate with it by executing that logic directly on the client. WebAssembly would be a solution.

    • Filing a technology gap

Google created an application called “Sqoosh”, the application is used for image compression and processing. The application takes advantage of API’s and processing that traditional JavaScript couldn’t achieve so they turned to WASM. This is a situation where WebAssembly can make the difference.

    • Making use of non-web friendly code

“Sqoosh” is also a good example of making use of non-web friendly code, it uses multiple libraries written in a variety of languages compiled into WASM to deliver a wide range of image processing functionality. The idea is, code exists already that does something you want to do on the web, maybe WASM can be the solution that brings that code to the web.

 

Demo

The code for this video can be found on github at https://github.com/rmroot/WebAssemblyLnL if you want to take a look at it yourself.

 

Summary

Here’s where I give you my opinion on WebAssembly. I have worked with it on and off over the last couple years to bring a C++ library to the web. It’s been a fascinating experience and WebAssembly was the only technology out there that would allow us to execute the C++ library on the client like we needed to. It’s been smooth but tedious sailing writing the bindings and integrating them into the web application. The hiccups only showed up when the C++ code got a little complex for a web developer in a C++ world. I’d say my first hand experience as a developer working with WebAssembly overall has been good! I’d say my experience as a user of an application built on WebAssembly has been great! The performance kick isn’t hype, as the demo shows, you’re able to run the same logic at a 50% speed increase. In some spots that is going to make or break an application’s success.

With that being said, I don’t think WebAssembly is the end-all be-all solution to all your web development needs. It’s not a JavaScript killer. More like a handy tool to help in certain situations. Many applications are just fine existing without it! BUT if you run into any of the use cases I listed above then know you can turn to WebAssembly with confidence. It has the support of all the right people and doesn’t seem to be going away or being replaced anytime soon!

 

 

About Intertech

Founded in 1991, Intertech delivers software development consulting to Fortune 500, Government, and Leading Technology institutions, along with real-world based corporate education services. Whether you are a company looking to partner with a team of technology leaders who provide solutions, mentor staff and add true business value, or a developer interested in working for a company that invests in its employees, we’d like to meet you. Learn more about Intertech, Inc.