text stringlengths 1 372 |
|---|
<topic_start> |
what you'll learn |
it’s been said that “a fast app is great, |
but a smooth app is even better.” |
if your app isn’t rendering smoothly, |
how do you fix it? where do you begin? |
this guide shows you where to start, |
steps to take, and tools that can help. |
info note |
<topic_end> |
<topic_start> |
diagnosing performance problems |
to diagnose an app with performance problems, you’ll enable |
the performance overlay to look at the UI and raster threads. |
(the raster thread was previously known as the GPU thread.) |
before you begin, you want to make sure that you’re running in |
profile mode, and that you’re not using an emulator. |
for best results, you might choose the slowest device that |
your users might use. |
<topic_end> |
<topic_start> |
connect to a physical device |
almost all performance debugging for flutter applications |
should be conducted on a physical android or iOS device, |
with your flutter application running in profile mode. |
using debug mode, or running apps on simulators |
or emulators, is generally not indicative of the final |
behavior of release mode builds. |
you should consider checking performance |
on the slowest device that your users might reasonably use. |
<topic_end> |
<topic_start> |
why you should run on a real device: |
<topic_end> |
<topic_start> |
run in profile mode |
flutter’s profile mode compiles and launches your application |
almost identically to release mode, but with just enough additional |
functionality to allow debugging performance problems. |
for example, profile mode provides tracing information to the |
profiling tools. |
info note |
DevTools can’t connect to a flutter web app running |
in profile mode. use chrome DevTools to |
generate timeline events for a web app. |
launch the app in profile mode as follows: |
in VS code, open your launch.json file, and set the |
flutterMode property to profile |
(when done profiling, change it back to release or debug): |
from the command line, use the --profile flag: |
for more information on the different modes, |
see flutter’s build modes. |
you’ll begin by opening DevTools and viewing |
the performance overlay, as discussed in the next section. |
<topic_end> |
<topic_start> |
launch DevTools |
DevTools provides features like profiling, examining the heap, |
displaying code coverage, enabling the performance overlay, |
and a step-by-step debugger. |
DevTools’ timeline view allows you to investigate the |
UI performance of your application on a frame-by-frame basis. |
once your app is running in profile mode, |
launch DevTools. |
<topic_end> |
<topic_start> |
the performance overlay |
the performance overlay displays statistics in two graphs |
that show where time is being spent in your app. if the UI |
is janky (skipping frames), these graphs help you figure out why. |
the graphs display on top of your running app, but they aren’t |
drawn like a normal widget—the flutter engine itself |
paints the overlay and only minimally impacts performance. |
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, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.