Sub topic 1
Debug, Profile, and Release: What Changes in a Release Build
Prerequisites
This chapter assumes that you know basic Dart and Flutter development. You should have the Flutter SDK installed and be comfortable running commands in a terminal. Android Studio is needed for Android builds. Xcode on macOS is needed for iOS builds.
A Flutter build mode controls how the application is compiled and which development tools remain available. Flutter provides three modes:
- Debug is for writing and inspecting code.
- Profile is for measuring performance.
- Release is for distributing the finished application.
The same Dart source can behave differently in each mode because the compiler and Flutter runtime use different settings.
| Mode | Main purpose | Typical features |
|---|---|---|
| Debug | Development | Hot reload, assertions, debugging tools |
| Profile | Performance testing | Tracing and performance measurements |
| Release | Distribution | Optimized code, no development service |
Debug mode
Debug mode is the default when you run:
flutter runIt supports hot reload, which updates the running application without rebuilding all of its state. Debug mode also enables assertions. An assertion checks that an assumption is true and reports an error when it is not.
Debug mode includes extra runtime checks and debugging support. These features make development easier, but they add overhead. A screen that appears smooth in debug mode can still perform poorly in a release build, and the opposite can also happen if debugging changes the timing of the application.
Do not use debug performance results to decide whether an application is ready for users.
Profile mode
Profile mode is designed to measure performance while keeping some profiling support available. Use it on a real device rather than an emulator when possible:
flutter run --profileProfile mode removes most debug overhead. It lets you inspect frame rendering, CPU work, memory use, and other performance data with Flutter's profiling tools. Hot reload and normal source-level debugging are not available in the same way as they are in debug mode.
Profile mode is useful for finding slow scrolling, expensive rebuilds, animation problems, and excessive memory use. It is still a diagnostic build, not the artifact you submit to an app store.
Release mode
Release mode applies compiler and runtime optimizations. It disables assertions, debugging service extensions, and hot reload. The application is compiled for end users, so startup time, code size, and runtime performance are closer to the shipped result.
Build and run a release version with:
flutter run --releaseTo create a distributable Android build, use a release command such as flutter build appbundle --release. Release builds must also be signed before distribution. iOS release builds use Xcode signing settings and require an appropriate Apple development setup.
A release build can expose problems hidden during development:
- An assertion may have been incorrectly relied on for validation.
- A debug-only service or local endpoint may not exist.
- A missing permission or signing setting may prevent installation.
- Environment values may point to the wrong backend.
- Logging and error reporting may provide less information.
Validate user input and handle errors in normal application code. Assertions are for developer assumptions, not security checks or required business logic.
Choosing a mode
Use debug mode for fast feedback. Use profile mode to measure behavior under realistic conditions. Use release mode for final acceptance testing and distribution.
Exercise
Why should a performance decision be based on profile or release mode instead of debug mode?
Show answer
Debug mode includes extra checks and development services that add overhead, so its timing and resource use may not represent the shipped application.