text stringlengths 1 474 |
|---|
Each graph represents the last 300 frames for that thread.This section describes how to enable the performance overlay |
and use it to diagnose the cause of jank in your application. |
The following screenshot shows the performance overlay running |
on the Flutter Gallery example: |
Performance overlay showing the raster thread (top), |
and UI thread (bottom).The vertical green bars |
represent the current frame.<topic_end> |
<topic_start> |
Interpreting the graphs |
The top graph (marked “GPU”) shows the time spent by |
the raster thread, the bottom one graph shows the time |
spent by the UI thread. |
The white lines across the graphs show 16ms increments |
along the vertical axis; if the graph ever goes over one |
of these lines then you are running at less than 60Hz. |
The horizontal axis represents frames. The graph is |
only updated when your application paints, |
so if it’s idle the graph stops moving.The overlay should always be viewed in profile mode, |
since debug mode performance is intentionally sacrificed |
in exchange for expensive asserts that are intended to aid |
development, and thus the results are misleading.Each frame should be created and displayed within 1/60th of |
a second (approximately 16ms). A frame exceeding this limit |
(in either graph) fails to display, resulting in jank, |
and a vertical red bar appears in one or both of the graphs. |
If a red bar appears in the UI graph, the Dart code is too |
expensive. If a red vertical bar appears in the GPU graph, |
the scene is too complicated to render quickly. |
The vertical red bars indicate that the current frame is |
expensive to both render and paint.When both graphs |
display red, start by diagnosing the UI thread.<topic_end> |
<topic_start> |
Flutter’s threads |
Flutter uses several threads to do its work, though |
only two of the threads are shown in the overlay. |
All of your Dart code runs on the UI thread. |
Although you have no direct access to any other thread, |
your actions on the UI thread have performance consequences |
on other threads.For links to more information and videos, |
see The Framework architecture on the |
GitHub wiki, and the community article, |
The Layer Cake.<topic_end> |
<topic_start> |
Displaying the performance overlay |
You can toggle display of the performance overlay as follows:<topic_end> |
<topic_start>Using the Flutter inspector |
The easiest way to enable the PerformanceOverlay widget is |
from the Flutter inspector, which is available in the |
Inspector view in DevTools. Simply click the |
Performance Overlay button to toggle the overlay |
on your running app.<topic_end> |
<topic_start>From the command line |
Toggle the performance overlay using the P key from |
the command line.<topic_end> |
<topic_start>Programmatically |
To enable the overlay programmatically, see |
Performance overlay, a section in the |
Debugging Flutter apps programmatically page.<topic_end> |
<topic_start> |
Identifying problems in the UI graph |
If the performance overlay shows red in the UI graph, |
start by profiling the Dart VM, even if the GPU graph |
also shows red.<topic_end> |
<topic_start> |
Identifying problems in the GPU graph |
Sometimes a scene results in a layer tree that is easy to construct, |
but expensive to render on the raster thread. When this happens, |
the UI graph has no red, but the GPU graph shows red. |
In this case, you’ll need to figure out what your code is doing |
that is causing rendering code to be slow. Specific kinds of workloads |
are more difficult for the GPU. They might involve unnecessary calls |
to saveLayer, intersecting opacities with multiple objects, |
and clips or shadows in specific situations.If you suspect that the source of the slowness is during an animation, |
click the Slow Animations button in the Flutter inspector |
to slow animations down by 5x. |
If you want more control on the speed, you can also do this |
programmatically.Is the slowness on the first frame, or on the whole animation? |
If it’s the whole animation, is clipping causing the slow down? |
Maybe there’s an alternative way of drawing the scene that doesn’t |
use clipping. For example, overlay opaque corners onto a square |
instead of clipping to a rounded rectangle. |
If it’s a static scene that’s being faded, rotated, or otherwise |
manipulated, a RepaintBoundary might help.<topic_end> |
<topic_start>Checking for offscreen layers |
The saveLayer method is one of the most expensive methods in |
the Flutter framework. It’s useful when applying post-processing |
to the scene, but it can slow your app and should be avoided if |
you don’t need it. Even if you don’t call saveLayer explicitly, |
implicit calls might happen on your behalf. You can check whether |
your scene is using saveLayer with the |
PerformanceOverlayLayer.checkerboardOffscreenLayers switch.Once the switch is enabled, run the app and look for any images |
that are outlined with a flickering box. The box flickers from |
frame to frame if a new frame is being rendered. For example, |
perhaps you have a group of objects with opacities that are rendered |
using saveLayer. In this case, it’s probably more performant to |
apply an opacity to each individual widget, rather than a parent |
widget higher up in the widget tree. The same goes for |
other potentially expensive operations, such as clipping or shadows.info Note |
Opacity, clipping, and shadows are not, in themselves, |
a bad idea. However, applying them to the top of the |
widget tree might cause extra calls to saveLayer, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.