text
stringlengths 1
372
|
|---|
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.
|
the platform’s main thread. plugin code runs here.
|
for more information, see the UIKit documentation for iOS,
|
or the MainThread documentation for android.
|
this thread is not shown in the performance overlay.
|
the UI thread executes dart code in the dart VM.
|
this thread includes code that you wrote, and code executed by
|
flutter’s framework on your app’s behalf.
|
when your app creates and displays a scene, the UI thread creates
|
a layer tree, a lightweight object containing device-agnostic
|
painting commands, and sends the layer tree to the raster thread to
|
be rendered on the device. don’t block this thread!
|
shown in the bottom row of the performance overlay.
|
the raster thread takes the layer tree and displays
|
it by talking to the GPU (graphic processing unit).
|
you cannot directly access the raster thread or its data but,
|
if this thread is slow, it’s a result of something you’ve done
|
in the dart code. skia and impeller, the graphics libraries,
|
run on this thread.
|
shown in the top row of the performance overlay.
|
this thread was previously known as the “gpu thread” because it
|
rasterizes for the GPU. but it is running on the CPU.
|
we renamed it to “raster thread” because many developers wrongly
|
(but understandably)
|
assumed the thread runs on the GPU unit.
|
performs expensive tasks (mostly I/O) that would
|
otherwise block either the UI or raster threads.
|
this thread is not shown in the performance overlay.
|
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>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.