Sub topic 1
Measure the right build: debug, profile and release
Prerequisites
You should know basic Flutter and Dart, including how to run an app and edit pubspec.yaml. You should also be comfortable using the command line and understand asynchronous Dart code.
Flutter has three build modes for different jobs:
- Debug is for development. It supports hot reload, assertions, debugging tools, and extra runtime checks.
- Profile is for performance investigation. It uses ahead-of-time compiled code like release mode, but keeps some tracing and profiling support.
- Release is for shipping. It applies the production optimizations and removes development tools.
The same application can have very different size and startup behavior in each mode. A debug build may contain extra code and metadata. It also runs with a less optimized execution path. Measuring it can make a normal release application look larger and slower than it really is.
Choose the mode for the question
Use debug mode to answer questions such as “Does this widget rebuild correctly?” and “Why does this button not respond?” Do not use it to compare launch time, frame rate, or download size.
Use profile mode when you need timeline data or want to investigate startup and rendering performance on a physical device. Profile mode is usually close to release mode, but its profiling hooks can add some overhead.
Use release mode when measuring the artifact that users will install. It is the right mode for final download-size checks, installation tests, and production-like startup checks.
The following commands make the mode explicit:
flutter run # Debug mode
flutter run --profile # Profile mode on a connected device
flutter build apk --release # Production APK
flutter build appbundle --releaseFor fair comparisons, keep the important conditions constant:
- Use the same device or emulator configuration.
- Test a fresh installation when measuring installation or first launch.
- Use the same network and test data.
- Repeat startup tests several times and record the median.
- Record the Flutter version, device model, operating-system version, and build mode.
Common measurement errors
A frequent error is comparing a debug APK with a release APK and treating the difference as an optimization result. That comparison mostly measures the build modes, not your code change.
Another error is using an emulator for a final performance decision. Emulators are useful for development, but their CPU, storage, graphics, and startup behavior may differ from a physical device.
Profile mode is also not the final artifact. Use it to find bottlenecks, then confirm the result in release mode. A change that improves a profile trace can still have a different effect after release optimizations.
A repeatable first check
Before changing code, build and measure a release artifact. Save its size and record startup observations. Then make one focused change and repeat the same test.
For performance work, begin with profile mode:
flutter run --profile --trace-startupFor shipping-size work, build the release artifact that your distribution channel uses. An Android App Bundle and an APK represent different delivery models, so compare the same artifact type over time.
Exercise
Which build mode should you use to investigate frame timing, and which mode should you use to measure the final shipped size?
Show answer
Use profile mode to investigate frame timing and release mode to measure the final shipped size.