The most useful tool for analyzing performance is the Observatory timeline, you can use it to quickly locate and diagnose problematic frames.
Unfortunately the observatory button was removed by the Flutter plugin, see IntelliJ Observatory for an easy way to open it again.
Keep in mind timelines can be skewed by external factors such as low memory, it’s always good to double check by enabling performance overlays in the developer options.
The DevTools timeline is also nice, but it has some limitations like not being able to get the class name of a sample. It also lacks the ability to analyze live objects, which is extremely helpful for tracking down memory leaks.
Until DevTools has feature parity, I would recommend learning how to use the Observatory instead.
My general workflow goes as follows:
- Run the app in profile mode.
- Open the observatory.
Click “view timeline” under VM information.
Click “Flutter Developer”:
- Prepare the device to produce problematic frames e.g. open the ListView.
Click clear in the top right.
- Perform the action that produces problematic frames.
- Click refresh.
Use the pan and zoom tools to locate a bad frame:
Make sure you scroll vertically to the ui and raster threads, bad frames will stick out like this:
For ui thread problems like shown above, click the timeline event and then find the overlapping samples:
Locate problematic functions in the samples below:
Here we can see the root cause of the jank, I’m doing too much work in a closure in
Unfortunately the culprit might not be a single function, but instead emerge from large complex widgets.