提高渲染性能

在衡量性能时,应用程序中的渲染动画一直是最受关注的话题之一。由于 Flutter 自带的 Skia 引擎以及它能够快速创建和处理组件的能力, Flutter 应用在默认情况下就能保证拥有良好的性能,因此我们只需避开常见的陷阱就可以获得出色的性能。

Rendering animations in your app is one of the most cited topics of interest when it comes to measuring performance. Thanks in part to Flutter’s Skia engine and its ability to quickly create and dispose of widgets, Flutter applications are performant by default, so you only need to avoid common pitfalls to achieve excellent performance.

如果看到不稳定(不流畅)的动画,请 确保 你正在做性能分析的应用是在 profile 模式下构建的,因为默认情况下 Flutter 会在 debug 模式下创建应用,这并不表示应用正式发布后的性能。更多信息,参见 Flutter 的构建模式

If you are seeing janky (non smooth) animations, make sure that you are profiling performance with an app built in profile mode. The default Flutter build creates an app in debug mode, which is not indicative of release performance. For information, see Flutter’s build modes.

有几种常见的陷阱:

A couple common pitfalls:

  • 每帧重建的 UI 比预期的要多得多。要跟踪组件的重建,请参阅 显示性能数据

    Rebuilding far more of the UI than expected each frame. To track widget rebuilds, see Show performance data.

  • 直接构建大量的子组件列表,而不使用 ListView。

    Building a large list of children directly, rather than using a ListView.

有关评估性能的更多资料(包括常见缺陷),请参阅以下文档:

For more information on evaluating performance including information on common pitfalls, see the following docs: