WebAssembly – power hidden in browser
31.05.2019 - Read in 6 min.
Or maybe you’ve been thinking about sharing your game, created in Unity
or Unreal Engine, to a broader audience through web browsers?3
A bit of history…
The need for performance
Native performance for everybody
I’m sure we all remember Adobe Flash, Java applets, or not-so-distant PNaCL
This opens a whole new perspective to companies that have been creating apps limited by a particular environment they were intended for.
How Autodesk used WebAssembly
Apart from higher performance of WebAssembly, the diagram depicts deviations occurring with each subsequent execution of the code.
Efficiency of finding exceptions in the source code map was tested (using a browser tool for code debugging significantly speeding-up the work of the developer).
Another important aspect is the cost. WebAssembly enables the use of an already written code, which can be recompiled in such a way to make it understandable to browsers.
Autodesk is not an exception
Other examples of large realisations with the use of WASM are Figma
– an app for designing interfaces simultaneously on various devices, and PSPDFKit, an app for generating PDF documents. I have described their experiences with WebAssembly in the context of benchmarks.
Graphic designers and computer game developers should be interested in
the fact that both Unreal Engine and Unity Engine are compiled to WASM.
An example of a game written in Unity that can be played in a browser.
The idea behind WebAssembly reaches beyond porting of apps written in low-level languages for browsers. Just take a look at Nebulet – an OS project with WebAssembly modules and WASM to machine code compiler. Therefore, we can expect that WASM will not only be a permanent part of browsers. It will be also a native component on various devices, which will open new possibilities e.g. for IoT (Internet of Things).
A few of the abovementioned companies decided to describe their experiences with WebAssembly and measure the increase in performance after moving to
WASM. The results shared by Figma speak volumes.5
Loading a large project in a browser app took over 3 times less in WASM in comparison to compiling it to its predecessor. On their blog, PSPDFKit have also shared benchmark results for their engine comprising 500.000 lines of code in C++, which is run in a browser thanks to WASM.
The charts above show that even though there’s still a long way to go for developers responsible for WASM support in browsers, the possibilities offered by the language are clearly visible. Over two times better result of WASM
a great achievement.6
A promising technology, but…
WebAssembly is a very young technology, and the programmers behind this project have still a lot of work to do.
At this moment, Rust, C, and C++ languages are the easiest to compile to WebAssembly. They all have one major feature in common – manual memory management.
WebAssembly still works to add a garbage collector or threading. It would naturally make it easier to compile the most popular languages used in major corporations, i.e. Java and C#. Obviously, compilers are already available (TeaVM or JWebAssembly for Java, Blazor for C#), but their capabilities are currently limited.
To sum up, milestones in the development of WASM will be:
Direct access to Brower API and DOM tree
Is it worth it?
WebAssembly is already supported by Golang – a language developed by Google. This is important because since Q1 2018, Portable Native Client is
no longer developed (contrary to WASM).
Microsoft also sees the potential of this language, which is why they took the C# compiler created for WebAssembly – Blazor – under their wings.
Browser support is also promising:7
Over 75% of all users can already use WebAssembly, and if a browser does not support WASM code. A compiler can be configured to create code in
a version supported by WASM’s predecessor – asm.js.
In my opinion, all of this suggests that the world needs WebAssembly and aims at making it a part of the Web Development canon as quickly as possible. We are given a tool that offers huge opportunities. Personally I can’t wait for a major project that will use WebAssembly as its primary solution.
Now, with blockchain and machine learning looming on the horizon, I don’t think I’ll wait long.
4. https://hacks.mozilla.org/2018/01/oxidizing-source-maps-with-rust-and-webass embly/