Learn from our software experts from the HAT everything you should know about Web Assembly, a programming language that solves some of Java’s problems.
Anyone that develops or designs for the Web is familiar with JavaScript. JavaScript is the gateway to any kind of interactivity that can be activated within the user terminal from a simple drop-down menu to complex applications such as vector graphics editors, music production studios, and multiplayer games.
The power and popularity of JavaScript is its versatility to run on any device that a web browser can interpret, that is, virtually anywhere. But this strength, which is its great capacity for abstraction, is also a major constraint when talking about the performance because of the need to interpret all the code. For this reason, Web Assembly was born .
Also called “WASM”, Web Assembly is a programming language that comes to solve this problem . Its goal is to compile code from C and C ++, achieving an interpretation and execution much faster than JavaScript without losing the independence from the platform in which it runs. This is because Apple, Google, Microsoft, and Mozilla are designing it all together (companies with 97% of the browsers market covered).
This involves a number of features that are not minor:
- It will open access to low-level programming for those programmers who want to use it. No objects or dynamic association or garbage collectors programming.
- The resulting code is binary, which is much smaller than the source code and much faster to run. You can also convert text format so that you can read.
- Binary modules can be integrated with traditional JavaScript natively without supplements.
- Some features close to the hardware (such as threads and microcontrollers) will be available for use.
- Graphic engines like Unreal Engine and other applications made in C or C ++ may be gathered in WebAssembly and be available on any platform. And they will have a speed of compilation and execution from 4 to 20 times faster compared to their counterparts in JavaScript.
The appearance of WebAssembly also hopes to provide a standard solution to this problem that had already attempted to solve from several approaches:
- If additional language features are needed (being strongly typed), a new one is created to operate at a higher level. For example typescript, Dart or CoffeeScript. The problem is that the result always ends up becoming a JavaScript code.
- If you are looking for performance, some features of JavaScript are limited (as in the case of Asm.js in Firefox) or a specific client browser is created, capable of running native processor instructions (ActiveX in IE, Google Chrome NaCl is created). The last one is problematic because it harms the visibility of the source code that is common on the Web.
Asm.js case is interesting because it is a subset of JavaScript instructions that only use arrangements, assignments, operations, and numeric data types. In this way, no extra memory is allocated, no garbage, and no permanent types. It is useful to visualize the next Asm.js code because it may be very similar to how it will WebAssembly:
1 if (a[k + 22 | 0] << 24 >> 24 === 30) { 2 if (a[k + 22 | 0] << 24 >> 24 === 30) { 3 h = b[k + 14 >> 1] | 0; 4 if ((h - 1 & 65535) > 1) { 5 break; 6 } 7 l = c[j >> 2] | 0; 8 p = (c[1384465] | 0) + 3 | 0; 9 if (p >>> 0 < 26) { 10 s = (2293760 >>> (p >>> 0) & 1 | 0) !== 0 ? 0 : -1e3; 11 } else { 12 s = -1e3; 13 } if (!(Vq(d, l, k | 0, h << 16 >> 16, s) | 0)) { 14 break; 15 } 16 g[(c[f >> 2] | 0) + (l * 112 & -1) + 56 >> 2] = +(b[k + 12 >> 1] << 16 >> 16 | 0); 17 23 g[(c[f >> 2] | 0) + (l * 112 & -1) + 56 >> 2] = +(b[k + 12 >> 1] << 16 >> 16 | 0); 18 g[(c[f >> 2] | 0) + (l * 112 & -1) + 56 >> 2] = +(b[k + 12 >> 1] << 16 >> 16 | 0); 19 20 g[(c[f >> 2] | 0) + (l * 112 & -1) + 56 >> 2] = +(b[k + 12 >> 1] << 16 >> 16 | 0); 21 g[(c[f >> 2] | 0) + (l * 112 & -1) + 56 >> 2] = +(b[k + 12 >> 1] << 16 >> 16 | 0); 22 g[(c[f >> 2] | 0) + (l * 112 & -1) + 56 >> 2] = +(b[k + 12 >> 1] << 16 >> 16 | 0); 23 h = (c[f >> 2] | 0) + (l * 112 & -1) + 60 | 0; 24 l = k + 28 | 0; 25 c[h >> 2] = c[l >> 2] | 0; 26 c[h + 4 >> 2] = c[l + 4 >> 2] | 0; 27 c[h + 8 >> 2] = c[l + 8 >> 2] | 0; 28 c[h + 12 >> 2] = c[l + 12 >> 2] | 0; 29 c[h + 16 >> 2] = c[l + 16 >> 2] | 0; 30 c[h + 20 >> 2] = c[l + 20 >> 2] | 0; 31 c[h + 24 >> 2] = c[l + 24 >> 2] | 0; 32 }
For those who know the game “Angry bots” (the template Unity game) and want to try it in your browser, you can do it in https://webassembly.github.io/demo/. You must have the beta version of browsers: Firefox Nightly or Chrome Canary and follow the instructions to activate WebAssembly. Activating WebAssembly doesn’t compromise safety; the runtime environment will always be encapsulated and it will adapt to the same license policies from the browser that contains it.
Web Assembly has no release date, and it will not replace JavaScript , but it will enrich the Web experience with other applications that don’t have yet their niche because they are very difficult to compile to the current language: video editors, P2P applications, image recognition, augmented reality, low-latency, CAD applications, visualization and scientific simulation, emulation platforms, POSIX, remote desktops, VPN and applications with heavy clients.
All these and more will see the light within a browser when Web Assembly completes its development and is available for use, defining once again Internet’s course.
Comments? Contact us for more information. We’ll quickly get back to you with the information you need.