令人遗憾的 GPU 渲染配置文件只有光标闪烁

Deplorable GPU rendering profile only with just the cursor blinking

这是一个让我很困惑的问题。我正在分析我正在开发的应用程序,并注意到每当我停止滚动 RecyclerView 时,GPU 配置文件就会开始显示可怕的统计数据。我不明白为什么会发生这种情况,屏幕上似乎没有任何内容在更新,直到我注意到 GPU 配置文件图表后面发生了一些与图表更新同步的变化。

这是光标在 EditText 视图中闪烁。

我不敢相信我开发了一个只有在光标闪烁时才会表现得如此糟糕的应用程序,所以我调查了其他应用程序,google 应用程序并发现问题无处不在并且它不限于我的应用程序。

以下是Gmail官方应用程序搜索框内光标闪烁的截图。

如您所见,GPU 配置文件不可接受。

有没有办法解决或避免这个问题?我记得当应用程序打开时什么都不做时,测试人员抱怨电池耗尽,但我当时认为这与套接字连接存在的错误有关。现在,当考虑到这个问题时,测试人员经常将他们的手机留在光标始终闪烁的同一屏幕上,这很可能是电池耗尽的原因,因此减少简单闪烁光标所产生的影响很重要。

请注意,我不打算重写光标,也不打算改变它的预期行为,我只是想减少闪烁光标对 GPU 的影响。

我认为您的问题已在此处报告:TextView cursor blink GPU rendering unusual 因为描述似乎与您的火焰图相符。

关闭问题的 Google 工程师 按预期工作 说:

This is actually working as intended - since the CPU is at very low load (no animations running or any work being done), it's running at a very low frequency and the rare frames it does push out are very slow to render. That's fine though - there's no visible jank occurring, since continuous frames aren't being produced. Visible jank can only occur when there's a continuity of motion being interrupted. If there was motion though, the CPU would clock up, and the frames would render much faster.

You'll see the same thing when music apps update their scrubbers only once every second, instead of at 60fps. Frames take a long time, but it's a big savings on battery life.

虽然这没有回答电池寿命的问题,但可以说最终用户不会花太多时间输入文本,如果在文本输入期间最终用户的注意力从屏幕上移开,则任一设备都会进入 idle/doze 模式,否则用户将使用不同的应用程序,而不是 harness/test 计划中的测试设备。

由于渲染文本很复杂,阅读 Android's Font Renderer by Romain Guy

可能会有所帮助