Sub topic 2
Choosing debug, profile, or release mode
This chapter assumes you know basic Dart syntax, asynchronous programming, and Flutter widgets. You should also know how to run a Flutter app on an emulator, simulator, or physical device.
Flutter has three main build modes:
- Debug mode is for writing and inspecting code.
- Profile mode is for measuring performance on a device.
- Release mode is for testing the app as users will receive it.
The mode changes how Flutter compiles and runs your Dart code. It also changes which DevTools features are available. Choosing the wrong mode can lead to misleading measurements or missing debugging information.
What each mode is for
| Mode | Main purpose | Typical tools and behavior |
|---|---|---|
| Debug | Develop and diagnose logic | Hot reload, assertions, breakpoints, logs, Widget Inspector |
| Profile | Measure real performance | Performance view, CPU Profiler, Memory view, tracing |
| Release | Test the shipped application | Optimized code, minimal diagnostics, no normal DevTools connection |
Debug mode
Debug mode prioritizes fast development. Flutter uses a development-oriented runtime that supports features such as hot reload and detailed error messages.
Assertions are enabled in debug mode. An assertion checks that a condition is true while the program runs. For example, Flutter can report an invalid state instead of silently continuing.
# Run the app in debug mode
flutter run
# Run on a particular device after checking available device IDs
flutter devices
flutter run -d <device-id>Debug mode is useful for:
- Setting breakpoints and stepping through Dart code.
- Inspecting the widget tree.
- Testing a layout change with hot reload.
- Reading detailed framework error messages.
- Adding and filtering logs.
Debug mode is usually slower than a shipped app. It can also use more memory. Therefore, a screen that appears to stutter in debug mode may work smoothly in profile or release mode.
Profile mode
Profile mode is designed for performance investigation. It compiles the app with performance characteristics closer to release mode while retaining tracing support for DevTools.
Use a physical device when possible. Emulators and simulators can have different CPU, GPU, and display behavior from real hardware.
# Run the app in profile mode on a connected device
flutter run --profile
# Start DevTools separately, then connect using the VM service URI
# printed by flutter run
dart devtoolsProfile mode is the right choice when investigating:
- Slow frames or visible animation stutter.
- Expensive widget builds or layout work.
- CPU-heavy functions.
- Memory growth during normal use.
- Startup time and screen transition performance.
Do not judge performance from debug mode alone. Debug-only checks, instrumentation, and compilation behavior can distort the result.
Release mode
Release mode applies production optimizations. Flutter removes or disables development features, and the compiler produces code intended for distribution.
# Build an Android release package
flutter build apk --release
# Build an iOS release application
flutter build ios --releaseRelease mode is useful for checking:
- Whether an optimization changes user-visible behavior.
- Startup and interaction behavior in the shipped build.
- Build size and packaging.
- Problems that appear only after compiler optimization.
You generally cannot attach DevTools to a release application because the debugging service is disabled. Keep diagnostic logging and test controls separate from release behavior. Never rely on debug assertions for required validation, because assertions do not run in release mode.
A practical selection rule
Use the symptom to select the mode:
A common error is profiling a debug build. Another is trying to diagnose a breakpoint in release mode. First reproduce the problem in the mode that supports the needed tool. Then repeat the relevant test in profile or release mode to check whether the result still matters to users.
When comparing performance, keep the test conditions stable:
- Use the same device.
- Use the same data set.
- Perform the same actions.
- Close unrelated applications when practical.
- Compare several runs instead of trusting one result.
A profile result is evidence about runtime performance. It is not proof that every release build behaves identically. Build configuration, platform, device, and compiler changes can still affect the final result.
Exercise
An animation stutters in debug mode, but you cannot reproduce the stutter in profile mode. Which mode should guide your performance decision, and what should you do next?
Show answer
Use profile mode as the main performance signal because it is closer to production behavior. Repeat the test on the target physical device with stable actions and data. If the stutter remains only in debug mode, investigate it as a development overhead rather than assuming users will see the same problem.