2014.12.10
With the release of the WebGL target in both Unreal Engine 4 and Unity3D 5 we were interested in the technologies behind the port to the javascript browser context.
Running large application at native speed in the browser is not only a milestone for the gamer community: we would better think about it as what might be called the “Web 3.0” or something like that in the few year coming. Business application, graphic intensive application and of course game running as if they were installed in the OS. This bright future is actually segmented by the five main vendor and their respective favoured web technology. Google has NaCL (Native Client) which is followed by Opera. Apple has FTL (Fourth Tier LLVM). Nobody knows what Microsoft has. And Mozilla has asm.
One technology seems to have taken a serious advantage on the others: the asm.js library. Asm allows a full compatibility between browser as it is because it is just pure javascript. It allows large low-level code to be compiled to its environment. Then it allows a first performance optimisation by shifting javascript code compilation in the AOT (Ahead Of Time) instead of the JIT (Just In Time). A second performance optimisation is then in the hand of vendors. They can optimise asm compelling code compilation as if it was native code. Firefox has this feature since its 22nd version. Then Safari apparently runs asm code almost as fast as Mozilla. Benchmarks show that Chrome too but like Apple nothing official yet.
Game company and game engine company are diving in this feature since months now. Mozilla has developed Emscripten, an open source C/C++ to LLVM compiler that produced asm optimised code directly from the C/C++ source. Unity3D support the project. As a result the cost to port large code to asm.js is very small but the source needs to respect some obvious policy to be able to run on browser (File API, no Thread sharing, etc…). Emscripten also natively embed OpenGLes 2.0 code and allows direct port to WebGL with tacit buffer management.
If other language can also be compiled by Emscripten, C and C++ are said to be “mature”. Most existing library are already ported like 2D, 3D physics engine or database handler. Unreal Engine and Unity3D webGL compiler are mainly based on asm standard and the playable benchmark and demo talk about the performance for themselves.
The ironical part of asm is that it is a heavy emulation of a strictly casted type management and C-like memory allocation. By getting rid off runtime variable cast and sanitising memory buffer at every call. This lead to get rid off the garbage collection as well which is the main bottleneck in large scale performance based project. It also means that smartphone implementation can be optimised the same way. So a webGL game can only run faster if compiled from an OpenGL/C source instead of a third party javascript libraries. Developing a game for the web should be done using a game engine.
From this strict memory management point of view, Web app and document based software could easily benefit from the asm paradigm. Yet there is no asm based web app demo online to be able to stress the performance compared to actual web-app IDE & Engine.
Classic website development is, by its design oriented nature and its maintenance agenda, somewhat different from its planning to its execution. Which is good as many would loose they job in this “Web 3.0” revision.
参照サイト