Learn the basic ideas behind WebAssembly, its pros and cons, and find out how it can help you with software development.
It helped them to develop web and mobile apps and even add some interactive features to them. Over the last few years, the programming landscape has changed a bit though, and a new option has emerged: WebAssembly.
What Is WebAssembly?
WebAssembly was first announced in 2015 and released later on, in March 2017. It has become a World Wide Web Consortium recommendation on December 5th, 2019, and ultimately received the Programming Languages Software Award from ACM SIGPLAN in 2021.
How Does WebAssembly Work?
How To Compile The Language Of Your Choice Into WebAssembly?
While working with WebAssembly, you just have to write code in a high-level language (picked by you from many that WebAssembly supports) and turn it into WebAssembly bytecode. This is quite simple and can be done in any of three ways:
Your source code is translated into WebAssembly through the language’s own compiler toolchain. Rust, C/C++, Kotlin/Native, and D now all have native ways to emit WebAssembly from compilers that support those languages.
If your chosen language doesn’t have native WebAssembly support in its toolchain, you still can use a third-party tool to convert your code to WebAssembly. Java, Lua, and the .Net language family – all of them have support tools like this.
In this case, the language itself is not translated into WebAssembly. Instead, a digital interpreter written in WebAssembly runs code written in the language of your choice. This is the most inconvenient approach, since the interpreter may be several megabytes of code, but it allows existing code written in the chosen language to run unchanged. Python and Ruby – both have interpreters translated to WebAssembly.
Why Is WebAssembly So Great?
The beauty of WebAssembly is that it’s simple and can work basically from anywhere. There’s no need for any download, no installation. In just one click you can compile your code. It’s safer than downloading and running a program directly on your computer because browsers have established security measures (such as sandboxing techniques) to protect you. Sandboxing means that the browser isolates third-party programs, preventing malicious or malfunctioning software from damaging or snooping on the rest of your computer. That keeps the running code from messing with your system. Also sharing your work is simple with WebAssembly. You can just easily generate links, which are simply clickable strings of code that you can put anywhere.
For now, we can confidently say that WebAssembly is one of the few realistically universal platforms that can help you make your application accessible on any device. It also allows you to maintain a single code base, which provides simpler updates and makes sure that every user can properly access your application.
WebAssembly’s Pros And Cons
As we’ve previously mentioned, WebAssembly is an innovative smart language to help you with your coding. Yet, it is still quite new and contantly developing. Let's take a quick look at the pros and cons of WebAssembly to better understand what it can offer.
What makes WebAssembly so helpful and such a good fit for the web:
WebAssembly was designed to reach high-speed performance. Because of the size of its binaries, they work faster and are faster to download. They are also faster to decode and execute. This is especially important if you have to work on slow networks.
One of the main goals of designing WebAssembly was its portability. To run any application on a device, it has to be compatible with the device’s processor architecture and operating system. That means compiling source code every time, depending on all possible combinations of operating systems and processors in the architecture that you want to support. With WebAssembly you need just one extra step and your app will run in almost every modern browser. The outcome is nearly native code with no installations, local security concerns, or used disk space.
WebAssembly is being used inside the browsers most of the time. This improves security because it isolates modules and gives them permissions only for certain parts of the file system (or other resources). Different modules are isolated from each other and limited in ways for possible contact with any malicious code.
5. easy debugging
WebAssembly binary files make debugging way easier than in many other languages.
So what issues can appear while using the WebAssembly?
Obviously, no matter how many pros we’ll mention, the truth is that WebAssembly still has its limitations. New features are being actively developed and the technology is constantly evolving, so it has to take its toll on some of the functionalities.
1. No garbage collection
2. No direct DOM access
3. No support in older browsers
This disadvantage is actually changing quite dynamically, since more and more browsers are being added to the list of those supported by WebAssembly. Nevertheless, some older browsers still don't have the availability to load the WebAssembly modules. However, this is a significant inconvenience since WebAssembly supports all major browsers. It’s currently supported by 74.93% of all global users and as many as 82.92% of desktop users. If you’re looking for the list of currently supported browsers, you will find it here: https://caniuse.com/#feat=wasm.
Availability in the browser and in the cloud
WebAssembly works perfectly fine inside most types of browsers. In this case, it is the browser that handles its access to operating system features. But you can also run WebAssembly outside the browser: on the server or on an IoT (Internet of Things) device, for example. Then some of the issues will work similarly to the cloud-native tools, such as handling the concept of a file system (which you will need for saving your code, configuration, and shared data) on services that have no file system. Giving your code full access to the operating system is not only hazardous and leaves you vulnerable to being hacked, but also ties the code to one specific operating system, expulsing the liberty that WebAssembly otherwise provides you.
Areas That Can Benefit Most Through WebAssembly
WebAssembly Working Group
Moreover, WebAssembly technology is developed as a web standard by the W3C WebAssembly Working Group. This is a huge and open collaborative effort of people from many tech brands worldwide. It joins the players from the whole tech industry and even wider, to combine the performance and security of an assembly-like language with the easiness of high-level native languages. The Bytecode Alliance created to reach that goal and set WebAssembly standards, already counts with an active participation of technology leaders such as Google, Fastly, Intel, Meta, Agora, Microsoft, and many others.
We hope that this portion of knowledge at least has sharpened your appetite for more. In case you want to learn more about WebAssembly or you just have some questions that need answering – please do not hesitate to contact us by clicking the link below.