play-co / devkit-core

11 stars 17 forks source link

Timestep webgl pipeline optim #73

Closed bchevalier closed 7 years ago

bchevalier commented 7 years ago

Overview

Simplification and optimization of WebGL rendering pipeline. Mainly 3 objects were the focus of the otpimizations: the flush and drawImage methods and the ContextStateStack class in WebGLContext2D.

Changes

Performance

Overall there seems to be an obvious performance gain in terms of CPU usage. As usual, the relative performance gain (5~20%) depends on the test, the device and measurement method.

Chrome - MacBook pro

Everwing - start menu - chrome profile

Before

everwing-startmenu-heavy

After

everwing-startmenu-heavy

The drawImage and flush methods are now faster, The set method has disappeared. also the % used by the program is remain roughly identical, meaning that the performance boost is reflected in the program usage.

Everwing - gameplay - chrome profile

Before

everwing-gameplay-heavy

After

everwing-gameplay-heavy

Here as well the drawImage, flush and set methods are optimized. % of program remain identical.

Everwing - gameplay - chrome profile compilation

The following screenshots show the average non-idle CPU time profiled by chrome across 6 gameplay runs > 10s:

Before

everwing-gameplay

After

everwing-gameplay

On this benchmark the gain appears consequent: (13.8 - 11) / 13.8 = 20% boost!

Everwing - gameplay - duration of engine tick method on chrome

Before

everwing-startmenu-engine-tick

After

everwing-startmenu-engine-tick

Here as well the performance gain is obvious: (0.66 - 0.56) / 0.66 = 15%

Chrome - iPhone 7

Everwing - start menu - safari profile

Before

everwing-startmenu-iphone7

After

everwing-startmenu-iphone7

Just as an chrome, the drawImage and set methods have been optimized. For some reason the flush method never appeared (self time too insignificant). Overall benefit is not obvious on this profile as the idle time usually is hidden under the drawElements self time. The optimized was possibly slow to kick in? It would seem so as subsequent profiles played in the favor of the changes.

Everwing - start menu - safari profile

Before

everwing-gameplay-iphone7

After

everwing-gameplay-iphone7

On this profile the performance boost is quite obvious (optimizer possibly played in favor of the changes) if we consider the idle time as being hidden in the drawElements self time: (32.6 - 24.1) / 32.6 = 26% boost

Conclusion

Overall I think this work will provide a 10~15% cpu boost (even though some profiles seem to indicate a higher gain). Analytics will tell us but slowest devices should now run Everwing at 55fps. Meaning that we probably are 2 optimizations away from providing an average of 60fps on the slowest devices on Everwing (up from 30fps 3 months ago).

rogueSkib commented 7 years ago

Awesome, love the engine performance boosts, looks good and working well for me