Skip to content

Lesson 8 of 9 · 28m

Performance in Production: Startup, Jank, Memory, and Honest Profiling

Measure real devices and release builds, use Flutter DevTools correctly, and fix the expensive layer instead of applying widget folklore.

Performance advice travels badly. "Use const" becomes a religion, while the actual problem is a 40 MB JSON decode on the UI isolate. "Use ListView.builder" is repeated to people already using it, while the image cache silently decodes giant assets. Production performance starts with measurement on real hardware in release mode.

Profile the build users actually run

Debug mode is a development tool with assertions and different compilation behavior. Profile and release modes tell you the truth:

flutter run --profile -d <device-id>
flutter build apk --profile

Use the slowest device you realistically support. A flagship phone hides sins that a mid-range Android device exposes immediately. For web, test throttled CPU and network. For desktop, test with realistic window resizing and multiple monitors, not just a maximized developer screen.

Startup has several different clocks

Users do not care when main() runs. They care when they can act. Measure distinct phases:

process/native start -> Flutter engine start -> first frame -> route ready -> interactive data ready

Common self-inflicted damage includes synchronous plugin initialization before first frame, eager network waterfalls, large font/asset discovery, database migration in the critical path, and analytics SDKs that start too much machinery. Defer work that does not affect the first meaningful interaction, but do not hide correctness problems by pushing them into unowned background futures.

Jank means missed frame deadlines

Flutter DevTools frame analysis separates UI work and raster work. UI jank often comes from large build/layout operations or expensive Dart on the main isolate. Raster jank often comes from complex painting, large images, shader compilation, or overdraw. The repair differs:

large decode/transform          move work off UI isolate
long synchronous build          split or simplify widget work
large image memory              resize/decode at display dimensions
complex blur/shadow layers      reduce effects or cache carefully
frequent full-tree rebuild      narrow invalidation boundaries

Do not sprinkle RepaintBoundary everywhere before measuring. It can increase memory and compositing cost.

Memory behavior is platform-shaped

Image caches, list views, video textures, platform views, and large offline data structures dominate memory profiles. ListView.builder helps because it creates children lazily, but it does not magically dispose images or controllers if your item state retains them. Watch for caches without eviction rules and listeners retained after route disposal.

A realistic list item pattern keeps expensive objects bounded:

ListView.builder(
  itemCount: items.length,
  cacheExtent: 800,
  itemBuilder: (context, index) {
    final item = items[index];
    return OrderTile(key: ValueKey(item.id), order: item);
  },
)

Then measure. Changing cacheExtent can reduce jank while increasing memory; there is no free setting.

Observe real users without spying on them

Crash reporting and performance monitoring should capture device class, OS, app version, route, operation timing, and error kind. It should not capture message contents, tokens, or gratuitous personal data. If you cannot aggregate the metric safely, redesign it. "We only collect everything on error" is not a privacy posture.

Field notes

  • Flutter inspector is useful in development, but it does not replace release-mode timing.
  • Low-end Android devices often expose image decode and memory pressure before desktop or iOS do.
  • Web performance includes download size; tree-shaking and deferred loading matter as much as frame time.
  • Desktop resizing can trigger continuous layout work. Test during active resize, not just final window size.
  • A performance regression without a baseline is an opinion. Record startup and interaction budgets per release.

Was this lesson helpful?

Sign in to rate