Back to Articles

Advanced

Performance Profiling in Flutter: Using DevTools

· 9 min read

Opening DevTools

When you start the app in debug or profile mode with flutter run, the terminal prints a DevTools connection address. Opening that address in a browser gets you into the Flutter DevTools interface. For realistic performance measurements, using flutter run --profile gives more accurate results, since it avoids debug mode's extra overhead (assert checks, the debug banner, and so on).

Performance View: Frame Times and Jank

The Performance view shows a timeline of how long each frame takes. At 60 FPS, Flutter needs to finish each frame in about 16 ms, and on a 120 Hz screen in about 8 ms. Frames that exceed this budget are marked in red and perceived as "jank" — visible stuttering. Clicking a frame shows exactly which operations ran on the UI thread and the raster thread and how long each took.

Track Widget Rebuilds: Finding Unnecessary Builds

Turning on "Track widget rebuilds" in the Performance view shows exactly which widgets were rebuilt on which frame. A widget that keeps rebuilding unexpectedly usually comes down to one of two causes: a widget that should be const but isn't, or a listener like ListenableBuilder/Consumer wrapping a wider widget tree than it needs to.

// The ENTIRE Column rebuilds on every change
Consumer<CartModel>(
  builder: (context, cart, _) {
    return Column(
      children: [
        const AppHeader(),
        CartSummary(total: cart.total),
        const Footer(),
      ],
    );
  },
)

// Only CartSummary rebuilds
Column(
  children: [
    const AppHeader(),
    Consumer<CartModel>(
      builder: (context, cart, _) => CartSummary(total: cart.total),
    ),
    const Footer(),
  ],
)

Memory View: Catching Leaks

The Memory view shows live memory usage as a graph and lets you take heap snapshots at specific points to compare object counts. If memory usage keeps climbing as you enter and leave a page and never comes back down, an AnimationController, StreamSubscription, or StreamController that isn't closed in dispose() is a common cause.

class _MyPageState extends State<MyPage> {
  late final AnimationController _controller;
  late final StreamSubscription<int> _subscription;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this, duration: const Duration(seconds: 1));
    _subscription = someStream.listen(_onData);
  }

  @override
  void dispose() {
    _controller.dispose();
    _subscription.cancel();
    super.dispose();
  }
}

CPU Profiler: Finding Heavy Functions

Jank isn't always caused by widget rebuilds; sometimes a synchronous, heavy computation running inside a build method is the culprit. Start a recording in the CPU Profiler, trigger the problematic interaction, stop the recording, and look at the flame chart. The widest and most frequently repeated call stacks point to the functions that need optimizing.

A Practical Tip: Reducing Jank With const and RepaintBoundary

If Track Widget Rebuilds shows a widget rebuilding often even though its content never changes, making it const gives Flutter a direct signal not to recreate that widget instance. If a small, frequently changing widget — an animated badge, say — sits inside a large and otherwise static widget tree, wrapping just that small widget in a RepaintBoundary keeps the change on its own layer and stops the expensive widgets around it from being redrawn.

Conclusion

DevTools turns a vague complaint like "the app is slow" into a concrete cause: the Performance view shows which frame, Track Widget Rebuilds shows which widget, the Memory view shows which object, and the CPU Profiler shows which function is responsible. Starting performance optimization from measurement rather than guesswork always gets you to a result faster.