性能评估

Flutter 性能入门

Flutter performance basics

什么是性能?为什么性能很重要?如何才能提升性能?

What is performance? Why is performance important? How do I improve performance?

我们的目标是回答这三个问题(主要是第三个)以及任何与之相关的话题。如果你有任何关于性能方面的问题,本文档可以作为解决你疑惑的起点。

Our goal is to answer those three questions (mainly the third one), and anything related to them. This document should serve as the single entry point or the root node of a tree of resources that addresses any questions that you have about performance.

前两个问题的答案比较哲学,对于正在阅读这篇文章的开发者而言,当他们需要解决特定的性能问题时,并没有什么帮助。所以,我们将它们放在了 附录

The answers to the first two questions are mostly philosophical, and not as helpful to many developers who visit this page with specific performance issues that need to be solved. Therefore, the answers to those questions are in the appendix.

为了提升性能,首先你需要一些可以量化的指标来验证问题和性能的提升。在 指标 页面,你可以看到一些现有的指标,以及哪些工具和 API 可以用于获取这些指标。

To improve performance, you first need metrics: some measurable numbers to verify the problems and improvements. In the metrics page, you’ll see which metrics are currently used, and which tools and APIs are available to get the metrics.

这里有一个 常见问题 的列表,你可以查询你的问题是否出现过或者已经被解答,以及是否有现成的解决方案。(你也可以查看 GitHub issues 里含有 性能 标签的内容。)

There is a list of Frequently asked questions, so you can find out if the questions you have or the problems you’re having were already answered or encountered, and whether there are existing solutions. (Alternatively, you can check the Flutter GitHub issue database using the performance label.)

最后,性能问题可以分为四类,对应 GitHub issue 里的四个标签:「流畅度」、「内存」、「应用大小」、和「功耗」。

Finally, the performance issues are divided into four categories. They correspond to the four labels that are used in the Flutter GitHub issue database: “perf: speed”, “perf: memory”, “perf: app size”, “perf: energy”.

其它内容均已归纳到这四个类别中。(注意:这些文档正在扩展中。)

The rest of the content is organized using those four categories. (Note that these docs are in the process of being expanded.)

流畅度

Speed

你的动画是否卡顿(不流畅)?学习如何评估和修复渲染问题。

Are your animations janky (not smooth)? Learn how to evaluate and fix rendering issues.

提高渲染性能

Improving rendering performance

内存

Memory

明智地使用内存

Using memory wisely

应用大小

App size

如何测量应用的体积。体积越小,下载就越快。

How to measure your app’s size. The smaller the size, the quicker it is to download.

测量应用的体积

Measuring your app’s size