1

I'm working on custom animation (screen blinking with 60fps) on Android, and I was very surprised that using of stupid setInterval(() => {...}, 0) works much better that the native android's Choreographer.

With setInterval(() => {...}, 0) I've got stable 60 FPS even on android 5 devices, but with Choreographer (that should work much efficiency, code below) I got drops to 50 FPS on powerful OnePlus 6 on Android 9.0

android.view.Choreographer.getInstance().postFrameCallback(...);

But if I write down setInterval(() => null); near the Choreographer callback definition - I will achieve stable FPS and low GPU utilisation (LOL, right?).

So I have created app on playground where everybody can test it. Turn on 'Profile GPU rendering' - 'On screen as bars' in 'developer options' menu and launch this simple app with simple loader on 2 pages - one with absolutely empty component, another one with setInterval(() => {}, 0)

https://play.nativescript.org/?id=yRTcJk&v=1

As result - empty component renders loader at 58-60 FPS with full GPU utilization (up to 60FPS line), but in component with empty setInterval - stable 60 FPS and 1/3 way to 60FPS utilization.

Can anybody say what is going on?

UPD: added GIF's (second one - with setInterval(() => null); )

Loader with empty component Loader with empty setInterval(,0) in component

sashok1337
  • 1,019
  • 1
  • 7
  • 14
  • See [SO Why is setTimeout(fn, 0) sometimes useful?](https://stackoverflow.com/questions/779379/why-is-settimeoutfn-0-sometimes-useful). Read it **ALL**, *some answers* are *wrong* ! – Jon Goodwin Sep 27 '19 at 17:24
  • @JonGoodwin sorry, but how is it applicable here? I talk about NativeScript and that fact, that any animation runs much better with ```setInterval(() => null)``` in controller. – sashok1337 Sep 27 '19 at 17:37
  • 'NativeScript' uses the underlying JavaScript functions, it's all there in the link. Have you read it ? – Jon Goodwin Sep 27 '19 at 18:08
  • @JonGoodwin yes, I read it. And I understand how this works in JS. But first of all I think that NS overrides setInterval/setTimeout function to pass them directly to native layer. And I don’t realise how can **empty** setInterval function speedup app's frame drawing time. – sashok1337 Sep 27 '19 at 18:20

0 Answers0