Binary format for the web
Queues, Modules, Layers
The project page describes WebAssembly as a "new portable, size- and load-time-efficient format suitable for compilation to the web." The features arise from the following design decisions.
WebAssembly generates code as a stack machine that uses a LIFO queue to process individual instructions. The instructions in WebAssembly, which regard the program flow as a sequence of blocks, use this value stack. The blocks comprise, for example, if
conditions and for
loops. This formal definition lets you deal efficiently with the resulting code as a binary representation, whereas asm.js uses a JavaScript subset as the output format.
The binary format lets you store and process the compiled code faster compared with interpreted source code. Compared with pure JavaScript code, the code presents more opportunities for optimization.
The JavaScript engine manages the storage area that is available to a WebAssembly instance (module). Each module runs in its own sandbox and thus has no way to manipulate inaccessible address ranges. Although this is the only option MVP provides, in the future, the developers hope to offer more memory management and usage options. Multiple threads will thus share a storage area.
The binary format defined by WebAssembly allows for encoding in three layers. Layer 0 encodes the bytecode instructions and associated data structures in a simple binary form. This coding is suitable for simple interactions and thus for just-in-time (JIT) scenarios, instrumentation tools, and debugging.
Layer 1 builds on Layer 0 and uses specific knowledge about the nature of the type of syntax tree and its nodes to establish structural compression. The latter allows for more efficient encoding of values, rearranging values in the module, and reducing structurally similar tree nodes. Finally, Layer 2 uses known compression algorithms, such as Gzip and Brotli, which are already available in browsers. In short: Layers 1 and 2 offer smaller file sizes, quicker load times, and the efficient use of existing technologies.
In addition to the binary format, WebAssembly defines a text format that is suitable for testing and debugging and allows developers to program directly on request. This makes it possible, among other things, to show the source code of a WebAssembly module running in the browser. This feature is already omnipresent in browsers and can be used, for example, in the JavaScript console.
The WebAssembly text format (WAT) [26] uses s-expressions syntax, which mainly consist of lists and brackets. This format is used by programming languages such as Lisp, among others.
WebAssembly Explorer
Mozilla is currently developing WebAssembly Explorer [27], which allows you to write C and C++ code in the browser and convert it directly to WebAssembly (Figure 5). This allows developers to see and analyze their own code in text format, while downloading the resulting WebAssembly code in a text or binary format.
Highly Efficient
As previously mentioned, WebAssembly is intended not only to run inside, but also outside, browser environments and is currently accomplished using Node.js. However, in the future, the idea is for it to work as a standalone module independent of the JavaScript engine. As the browser module, WebAssembly is part of the Open Web Platform [28]; therefore, all features that are already part of the JavaScript Web API are available. WebAssembly is by no means a replacement for JavaScript in browser environments but will complement it and offers the opportunity to port other features and applications to the browser.
According to the design, the binary format ensures the most efficient execution possible, regardless of operating system and architecture. It relies on various features of the underlying hardware and operating system, but even if the JavaScript engine does not offer these features, it can still run the WebAssembly code. In this case, it must emulate the desired behavior, which can affect execution speed.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.