Worker Asynchronous Computation
1. Overview
In each frame of a minigame, the JS main thread mainly does two things: computation and rendering. Correspondingly, the Frame Time of each frame = computation time + rendering time. According to RAIL, the user-perceived performance model proposed by the Chrome team, the JS execution time (i.e., computation time) during animation playback should be less than 16ms, and should ideally be below 10ms, leaving a spare 6ms for rendering. Therefore, for minigames, the 16ms of each frame is very important.
However, in minigames, some complex computations (such as physics engine simulation) take an amount of time that is hard to guarantee will be below 10ms, which often causes the game frame rate to drop and stutter to occur. In particular, iOS's JavaScriptCore cannot enable JIT, which may cause minigames to perform very poorly on iOS.
Therefore, the Runtime provides the Worker asynchronous computation capability, offloading complex computations to a Worker. This can improve running efficiency by more than tenfold.
2. Effects
The main thread's computation time is greatly reduced
The main thread has ample time for rendering
Stable frame rate
Complex physics scenes no longer stutter
