NativeScript / NativeScript/android

setInterval(()=>null,0) makes any animation much smoother

Open
#1,491 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
563
Forks
144
Avg merge
10h 46m
Merged PRs (30d)
14

Description

Environment

  • CLI: 6.1.2
  • Android Runtime: 6.0.2 / 6.1.2

Describe the bug
I'm working on custom animation (screen blinking at 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?).

To Reproduce
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) in OnInit.

Sample project
Nativescript Playground

Additional context
I've recorded animations to demonstrate this behaviour Imgur
And my question on StackOverflow (without any answer) link

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the linked NativeScript Playground on Android with Profile GPU rendering enabled, comparing the empty screen, setInterval(..., 0), and Choreographer.postFrameCallback cases. Then trace the Android runtime scheduling entry points for setInterval and Choreographer; done means explaining or correcting the frame-rate difference and verifying the comparison on the reported devices.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, javascript
Domain
mobile-dev, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.