Sub topic 4
Running in Profile Mode and Opening the Performance View
Prerequisites
This chapter assumes that you can build a basic Flutter app, use flutter run, and work with widgets and build methods. You also need a connected physical device or emulator, a working Flutter SDK, and Flutter DevTools.
Flutter DevTools is a set of tools for inspecting and profiling a running Flutter app. Its Performance view records frame timing so you can investigate slow frames.
Why profile mode matters
Flutter has three common build modes:
| Mode | Main purpose | Performance measurement |
|---|---|---|
| Debug | Development and debugging | Often misleading because of extra checks and instrumentation |
| Profile | Performance investigation | Close to release behavior with profiling tools enabled |
| Release | Production distribution | Fastest, but profiling access is limited |
Debug mode helps you develop quickly, but it adds overhead. For example, assertions, debug checks, and some diagnostic work can make frames slower than they are in production. Release mode removes the tools you need to inspect the running application.
Profile mode provides the useful middle ground. The app runs with performance characteristics close to release mode while still exposing a Dart VM service that DevTools can use.
Start the app in profile mode
First, list the devices that Flutter can use:
flutter devices
flutter run --profile -d <device-id>Replace <device-id> with the identifier from the flutter devices output. For example, the command might look like this:
flutter run --profile -d emulator-5554Use a physical device when possible. An emulator can show useful trends, but its CPU, GPU, and display timing may differ from a user's device.
Interact with the app after it starts. Open the screen you want to study and repeat the action that might cause slow frames. Do not measure only the startup screen if the suspected problem occurs during scrolling, navigation, animation, or data loading.
Open DevTools
Flutter usually prints a DevTools URL in the terminal when the app starts. Open that URL in a browser, then choose the Performance view.
You can also start DevTools separately:
dart devtoolsOpen the displayed DevTools address in a browser. Connect it to the Dart VM service for the profile-mode application. In an IDE, you can usually use its Flutter or Dart DevTools command and select the running profile application.
The Performance view contains recording controls and a timeline. Start recording, perform the action you want to measure, and stop recording. Keep the recording focused. A short trace containing one interaction is easier to understand than a long trace containing unrelated activity.
Confirm that the connection is correct
Before drawing conclusions, check these details:
- The selected application is the profile-mode process, not another running app.
- The Performance view is recording the intended device.
- The app is idle before you begin the test.
- You repeat the same interaction when comparing two measurements.
- You test with representative data, images, and screen dimensions.
A profile trace is evidence about a particular device and workload. It is not a universal performance guarantee. A frame that is acceptable on a desktop emulator can still exceed the budget on a lower-powered phone.
First recording
Make one short recording now. Start the Performance view recording, navigate to a screen with a list or animation, scroll or interact once, and stop recording. The next step is to read the Flutter frames chart and determine whether the UI thread or raster thread caused any slow frames.
Exercise
Why should you use profile mode instead of debug mode when measuring Flutter frame performance?
Show answer
Profile mode keeps profiling access while avoiding much of the extra overhead that debug mode adds, so its timings are closer to release behavior.