WebAssembly Threads

WebAssembly Threads

Threads allow the runtime to use more than a single processor at a time. Apart from additional performance, this enabled simultaneously doing two or more tasks at once. The most noticable impact this has for Wonderland Engine is the now smooth framerate while transcoding basis textures.

Browser support 

WebAssembly threads are enabled since Chrome Desktop 74 / Chrome Android 88 by default.

Since Oculus Browser closely follows Chrome for Android releases, this means, Oculus Quest and Oculus Quest 2 will be able to harness the power of WebAssembly threads in their upcoming version.

Firefox supports WebAssembly threads since 79.0, which was released on July 28, 2020.

Use for Game Engines 

Threads allow doing work simultaneously or simply doing work with more power.

With the later, CPU heavy tasks can be sped up, like transcoding multiple Basis textures at the same time.

The former allows running rendering alongside CPU heavy tasks that span a big portion of or more than a single frame.

Apart from loading assets, physics is a great example of this. While starting to render the static parts of the scene, a game engine may simultaneously simulate the dynamic objects.

Significance for WebXR 

In WebXR, especially for Virtual Reality, rendering at a smooth framerate should be the number one priority of your application.

Since that usually takes up most of the processing power and leaves only small chunks of a few milliseconds, it is really hard to do longer processing tasks without hitches.

To do these kinds of tasks, you need to use a service worker / thread to allow rendering to continue while they run.

Implementation in Wonderland Engine 

With the 0.7.3 release Wonderland Engine makes use of WebAssembly threads through an internal job system if available.

If not available, it will fall back to loading a runtime that runs without threads. You will find one of the first lines in the browser console to be either “WASM Threads is supported” or “WASM Threads is not supported”.

While the Wonderland Engine currently only uses the job system to speed up and smoothen the initial loading of the scene, we will gradually move more and more tasks into threads. This will improve the performance of your projects without you needing to change anything.

Last Update: October 30, 2020

Stay up to date.