BabylonNative icon indicating copy to clipboard operation
BabylonNative copied to clipboard

Make `setTimeout` asynchronous and add `clearTimeout`

Open docEdub opened this issue 2 years ago • 2 comments

Overview

Improves setTimeout performance by making it asynchronous, and implements clearTimeout.

Details

The current implementation of setTimeout dispatches repeatedly until the given delay is reached. This causes performance issues.

This PR fixes the issue by building on the initial investigative work done in PR https://github.com/BabylonJS/BabylonNative/issues/843 to implement setTimeout asynchronously on a separate thread.

The clearTimeout function is currently not implemented and since it is closely related to setTimeout, it makes sense to implement it in this change, too.

Related tickets

https://github.com/BabylonJS/BabylonNative/issues/253 https://github.com/BabylonJS/BabylonNative/issues/893

docEdub avatar Oct 05 '22 20:10 docEdub

It might also be good to add some unit tests.

bghgary avatar Oct 06 '22 21:10 bghgary

@docEdub Don't forget to add unit tests here: https://github.com/BabylonJS/BabylonNative/blob/master/Apps/UnitTests/Scripts/tests.js It's handy because it runs on Mac and Linux as well.

CedricGuillemet avatar Oct 07 '22 08:10 CedricGuillemet