play-co / timestep

GNU General Public License v3.0
16 stars 27 forks source link

Optimization of wrapRender method #126

Closed bchevalier closed 7 years ago

bchevalier commented 7 years ago

Why

The wrapRender method could become de-optimized after a playing for a while. Also the method was called for many invisible views (ineffective calls to the method). The idea was to try to stop the de-optimization from happening and improving the subview system to make sure that invisible views wouldn't create overhead in the rendering pipeline. A few other implementation details surrounding the wrapRender method could be fixed.

How

Result

Chrome (macbook) profiling

Before

chrome-before

After

chrome-after

The wrapRender method in itself went from number 1 to number 2. The _renderSubviews method has now completely disappeared. They accounted for 16.5% of the resources before the refactoring down to 9% after.

Safari (iPhone 7) profiling

Before

screen shot 2017-06-14 at 4 10 49 pm

After

screen shot 2017-06-14 at 4 07 10 pm

The wrapTick + _renderSubviews method went from ~11% to 6%.

Chrome (macbook) measure

The measurements of the Engine's tick also are showing good improvements Before

screen shot 2017-06-13 at 1 45 03 pm

After

screen shot 2017-06-14 at 7 15 09 pm

The FPS in gameplay phase on Xperia Z3 seems to be higher, now in the 50~60fps range in light gameplay.

The gameplay benchmark shows an non-idle time of 11.64%, down from 13.5%! (still on my machine) Overall it looks like another ~10% CPU gain.

Sorting

The new sorting seems to give better performance. To test it I enforced the sort to happen every frame for every view: Before

screen shot 2017-06-14 at 7 01 49 pm

After

screen shot 2017-06-14 at 7 05 21 pm

Total time taken by the sorting is down from 10% to 4%. Conclusion: using a comparison method for sorting appears more efficient than sorting elements as strings. Of course the in-game benefit is smaller but considering the sorting now happens more often I thought it might be best to optimize the sorting.

Note: Refactoring of dom ViewBacking not tested!

bchevalier commented 7 years ago

updated!