Sub topic 7
Using Frame Analysis to Find the Likely Cause
Assume you can build and run a Flutter app, use flutter run, and recognize widgets, build methods, and StatefulWidget. You should also have a device or emulator running in profile mode with the DevTools Performance view open.
A slow frame tells you that something missed its deadline. It does not tell you which operation caused the delay. Frame Analysis narrows the search by summarizing the selected frame and its work on the UI and raster threads.
Select a slow frame
Start by reproducing the action that causes jank, such as scrolling a list or opening a page. In the Flutter frames chart, look for a bar that crosses the frame budget line. Select that frame.
The Performance view then shows information for the selected frame. Depending on the Flutter and DevTools version, the labels may differ slightly, but the useful questions remain the same:
- How long did the UI thread take?
- How long did the raster thread take?
- Which events consumed the most time?
- Did shader compilation or another one-time operation occur?
- Does the frame contain unusually expensive build, layout, paint, or raster work?
Frame Analysis is a guide, not a proof. It identifies suspicious work. You confirm the cause by inspecting the related timeline events and then reproducing the frame after a change.
Interpret the analysis
Use the thread timings to choose your first investigation:
| Observation | Likely area | What to inspect |
|---|---|---|
| UI time exceeds the budget | Dart code or framework work | Builds, layout, callbacks, parsing, and computation |
| Raster time exceeds the budget | Drawing or GPU work | Paint operations, large images, clips, shadows, and shaders |
| Both threads are high | Multiple costs or a busy frame | The longest events on each thread |
| A one-time spike appears | Initialization or shader work | The first frame after navigation or a visual effect |
A high UI time often comes from doing too much work during a rebuild. Examples include filtering a large collection, decoding data, sorting records, or running a long loop inside build. Rebuilding many descendants can also make layout and build events expensive.
A high raster time points to the cost of producing pixels. Large transparent images, complex clipping, repeated shadows, and oversized custom painting can increase that cost. A frame that is slow only the first time an animation or effect appears may involve shader compilation.
Do not infer the cause from the widget name alone. A widget may appear in the trace because it triggered work, while the expensive operation is in a callback, inherited widget update, custom painter, or image operation.
Connect Frame Analysis to the timeline
After reading the summary, open the detailed timeline for the same frame. Expand the UI and raster tracks and find events whose duration matches the reported delay.
For UI-thread jank, look for long Dart callbacks, repeated build events, layout passes, or expensive application functions. For raster-thread jank, inspect paint and compositor events. Compare event start and end times so that you do not confuse many short events with one long event.
Use Frame Analysis to form a testable statement:
> “This frame is slow because sorting runs during a rebuild.”
Then change only that area. Move the sort outside the rebuild path, cache its result, reduce the data, or perform suitable computation in an isolate. Measure the same interaction again.
Exercise
The selected frame has 8 ms of UI work and 24 ms of raster work. Which area should you inspect first, and why?
Show answer
Inspect raster-related work first. The raster thread is taking most of the frame time, so examine painting, images, clips, shadows, custom painting, and shader activity before changing Dart build logic.