Performance Optimization and Isolates

Google Flutter 12 min min read Updated: Nov 16, 2026 Advanced
Performance Optimization and Isolates
Advanced Topic 6 of 7

What is Good Performance?

A screen refreshes about 60 times per second (or 120 on fast phones). Each frame has roughly 16 milliseconds for building and drawing. If your code takes longer, frames are dropped and the app feels stuttery. This is called jank.

Measure first: Always test performance in profile mode on a real device: flutter run --profile. Debug mode is intentionally slow, and emulators do not show real speed.

1. Use const Widgets

dart // Better: Flutter reuses this widget and skips rebuilding it const Padding( padding: EdgeInsets.all(16), child: Text('Static text'), )

2. Make Rebuilds Small

  • Call setState in the smallest widget that needs it
  • Split big build methods into small widgets (as classes, not helper functions)
  • Use ValueListenableBuilder, Consumer or ref.watch on small parts
  • Use context.select or Selector to listen to only one field
dart // Prefer a separate widget class... class PriceTag extends StatelessWidget { final double price; const PriceTag(this.price, {super.key}); @override Widget build(BuildContext context) => Text('\$$price'); } // ...over a function that returns a widget. A class can be const and skipped by Flutter. Widget priceTag(double price) => Text('\$$price');

3. Do Not Do Heavy Work in build()

build runs often. Do not sort big lists, parse JSON or call APIs inside it. Prepare the data in initState, in your state management class or in a repository.

4. Use Lazy Lists

Use ListView.builder and GridView.builder. Avoid ListView(children: [...hundreds of widgets]) and avoid shrinkWrap: true on long lists, because it forces all items to be measured.

5. Handle Images Wisely

  • Resize large images on the server, or load a smaller size
  • Use cacheWidth / cacheHeight so Flutter decodes a smaller bitmap
  • Use the cached_network_image package to cache downloads
dart Image.network(url, cacheWidth: 400)

6. Expensive Effects

Opacity, ClipRRect, big shadows and saveLayer operations can be costly, especially in animations. Prefer AnimatedOpacity or FadeTransition, and use RepaintBoundary around parts that animate by themselves.

7. Move Heavy Work to an Isolate

Dart runs your UI code in one thread (the main isolate). A heavy calculation there freezes the screen. An isolate is a separate worker with its own memory, so it does not block the UI.

dart import 'package:flutter/foundation.dart'; import 'dart:convert'; // Heavy parse on a big JSON string List<Product> parseProducts(String body) { final list = jsonDecode(body) as List; return list.map((e) => Product.fromJson(e as Map<String, dynamic>)).toList(); } Future<List<Product>> loadProducts(String body) { return compute(parseProducts, body); // runs in another isolate }
dart import 'dart:isolate'; // Dart 3 way: Isolate.run final result = await Isolate.run(() { var sum = 0; for (var i = 0; i < 500000000; i++) { sum += i % 7; } return sum; });
Rule for isolates: The function must not depend on UI objects or widgets. Pass only simple data in, and get simple data back.

8. Profile with DevTools

  1. Run flutter run --profile.
  2. Open the Performance tab in DevTools.
  3. Look at the frame chart. Red bars are slow frames.
  4. Use Track widget rebuilds to find widgets that rebuild too often.

Quick Checklist

CheckDone?
const constructors everywhere possibleYes
Small widgets, local stateYes
Builder constructors for listsYes
Images are resized and cachedYes
Heavy work in isolatesYes
Tested in profile mode on a real deviceYes

Conclusion

Most performance problems come from rebuilding too much or doing heavy work on the main thread. Measure, then fix the real bottleneck.

Quick Summary: Use const, small widgets, builder lists, image caching and isolates, and measure with DevTools in profile mode.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators