NativeScript / NativeScript/android

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

未关闭
#1,491 10 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
C++
星标
563
派生
144
平均合并
10 小时 46 分钟
30 天内合并 PR
14

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,在启用 Profile GPU rendering 的 Android 上复现链接的 NativeScript Playground,并比较空屏幕、setInterval(..., 0) 和 Choreographer.postFrameCallback 的情况。然后跟踪 Android runtime 中用于调度 setInterval 和 Choreographer 的入口点;完成的标准是解释或修正帧率差异,并在报告中提到的设备上验证该比较。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, javascript
领域
mobile-dev, performance
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。