Skip to main content

04 - Flutter Performance: Impeller, Frame Times and Jank

At 60 Hz you get 16.67 ms per frame: read buildDuration and rasterDuration to see which thread overruns, and where Impeller is really the active renderer.

What do you think about this article?

At a Glance

At 60 Hz you get 16.67 ms per frame: read buildDuration and rasterDuration to see which thread overruns, and where Impeller is really the active renderer.

A 60 Hz screen gives you 16.67 milliseconds per frame: 1000 divided by 60. Within that window Flutter has to run your Dart code, compute the layout, build the layer tree and have the GPU draw it. If the sum overruns, that frame arrives late and the user sees a stutter.

Jank is therefore not a vague problem: it is a budget exceeded, and Flutter tells you which of the two halves exceeded it. This article shows how to read that figure, what Impeller solved and what it did not, and the four fixes that make a list faster - because it is always a list.

The Dart code in this article was analyzed

The Dart blocks were put into a real Flutter project and passed to the analyzer: flutter analyze on Flutter 3.44.2 (stable, revision c9a6c48423) answers "No issues found!". That means they compile and use no nonexistent APIs; it does not mean I ran them on a device, because this machine has neither an Android emulator nor an iOS simulator. The performance numbers you will see are the ones you will read from your own tools, not measurements of mine.

Impeller: what it solved, and where it is really active

The previous renderer, Skia, compiled shaders when they were needed, that is during execution: the first time a graphic effect appeared, the compilation happened at that moment and the frame was dropped. It was the characteristic defect of Flutter apps: the first scroll was choppy, the following ones smooth.

Impeller precompiles the shaders when you build the app, so at runtime it compiles none. The "first-frame jank" from shader compilation disappears by construction, not by optimization.

Two numbers and a flag name that circulate wrongly

The previous version of this article said that Impeller is the default "on iOS since Flutter 3.10 and on Android 10+ since Flutter 3.24". The official documentation says something else: it is the default for iOS and Android API 29+ from release 3.27. It also said that shader compilation caused "a freeze of 50-500 ms": that range has no source, and I removed it instead of softening it.

And the flag to go back to Skia is not --disable-impeller: the documented form is --no-enable-impeller. On this machine I could not verify it by running it, because flutter run --help shows that option only with a target platform configured; the source is the Impeller page, linked at the bottom.

The state by platform, as of 2026-11-08, is this:

  • iOS: Impeller is the only renderer, you cannot go back to Skia
  • Android API 29+: active by default; below that version, or without Vulkan support, it automatically falls back to the old OpenGL renderer
  • macOS and Windows: active by default from release 3.47, and the ability to turn it off will be removed
  • Web: still Skia

The criterion that orders these lines is how much control you are left with, and it decreases from top to bottom: on iOS you have no choice, on Android you have it but do not always need it, on desktop you will have it only for a short while. The line that weighs in daily work is the second, because it describes a silent fallback: on an old phone your app uses a different renderer from the one you tried it on, and the shader jank you thought was solved comes back only on those devices. The fourth line is the one people forget: if you also publish to the web, that build has none of what you have just read.

The useful consequence is that Impeller closed one category of jank. Needless widget rebuilds, heavy work on the UI thread and images decoded too large are independent of the renderer, and they are what you will deal with from here on.

The two threads, and the figure that separates them

Flutter splits the work of a frame between two threads. On the UI thread your Dart code runs: gestures, build(), layout, construction of the layer tree. On the raster thread, in C++, that tree becomes commands for the GPU.

Knowing which of the two overran completely changes the diagnosis, because the cures are opposite: a slow UI thread is cured by reducing the Dart work, a slow raster thread by reducing the complexity of what you draw. Flutter exposes the two times separately, and you can read them from code.

Counting late frames, telling UI and raster apart
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

/// Frame budget derived from the screen refresh rate.
Duration budgetPerFrame(double refreshHz) =>
    Duration(microseconds: (1000000 / refreshHz).round());

class FrameWatch extends StatefulWidget {
  const FrameWatch({required this.child, this.refreshHz = 60, super.key});
  final Widget child;
  final double refreshHz;

  @override
  State<FrameWatch> createState() => _FrameWatchState();
}

class _FrameWatchState extends State<FrameWatch> {
  int _late = 0;
  int _total = 0;

  @override
  void initState() {
    super.initState();
    SchedulerBinding.instance.addTimingsCallback(_onTimings);
  }

  @override
  void dispose() {
    SchedulerBinding.instance.removeTimingsCallback(_onTimings);
    super.dispose();
  }

  void _onTimings(List<FrameTiming> timings) {
    final budget = budgetPerFrame(widget.refreshHz);
    for (final t in timings) {
      _total++;
      if (t.totalSpan > budget) {
        _late++;
        debugPrint('slow frame: build=${t.buildDuration.inMicroseconds}us '
            'raster=${t.rasterDuration.inMicroseconds}us '
            'total=${t.totalSpan.inMicroseconds}us '
            'budget=${budget.inMicroseconds}us');
      }
    }
  }

  @override
  Widget build(BuildContext context) => widget.child;
}

The mechanism is addTimingsCallback: Flutter hands you, in batches, a FrameTiming for every frame already completed. It is not a profiler that slows the app down - it receives data that the engine collects anyway - so you can keep it active even in a profile build.

The three fields you will use are buildDuration, the time of the UI thread, rasterDuration, the time of the raster thread, and totalSpan, the overall span of the frame. The comparison is made on totalSpan, because a frame is late if as a whole it overran; the first two then tell you whom to blame.

The line not to forget is removeTimingsCallback in dispose. Without it, the callback stays registered on the binding even after the widget has left the tree: the old State is not released and, if the widget is rebuilt several times, you accumulate callbacks that all do the same work. It is a classic memory leak, and it produces no visible error.

A clarification on refreshHz = 60: it is a convenience value, not a truth. Many devices run at 90 or 120 Hz, and at 120 Hz the budget drops to 8.33 ms, that is half. The correct way to obtain it is to read the rate from the display instead of writing it by hand, otherwise on a fast phone you count as "late" frames that were in fact on time.

Profiling: the right mode and what to look at

Before any measurement, a rule that saves hours: you do not profile in debug. In that mode the Dart code is interpreted by the JIT, assertions are active and the timings are much slower than the real ones.

Starting in profile mode and opening the tools
# The mode for measuring: AOT-compiled, but with the instrumentation on
flutter run --profile

# DevTools is included in the SDK: it no longer needs to be installed with `pub global activate`
dart devtools

# Chart overlay directly in the app, without DevTools:
# two bands on top of the screen, UI above and raster below.
flutter run --profile --dart-define=x=y   # then 'P' in the console for the overlay

The three modes are not interchangeable: debug is for developing and has hot reload, profile compiles like production but keeps the measuring tools, release removes those too. Measuring in debug leads you to optimize code that was not slow in production.

The line about dart devtools corrects an instruction that still circulates: DevTools is shipped with the SDK, so the old flutter pub global activate devtools is not needed and may install a different version from that of your SDK. In the performance overlay the two bands are read like this: the upper one is the UI thread, the lower one the raster, and the vertical line is the budget - the bars that cross it are the dropped frames.

In the DevTools timeline the useful reflex is to click a red frame and look at which of the two threads is long. If it is the UI thread, look for expensive build() calls; if it is the raster, look for overlapping draws, opacity and clips applied to large subtrees.

The four fixes that really pay off

In order of benefit to effort: const on static widgets, RepaintBoundary around what animates, decoding images at the right size, and a declared row height in lists.

1. const: a widget that is not rebuilt

When a parent widget rebuilds, Flutter reprocesses its children. A child declared const is the same instance on every pass, so the comparison is immediate and the subtree is skipped.

The difference of one word
// Recreated on every rebuild of the parent: new instance, comparison fails
Text('Loading')

// Same instance for the whole life of the app: the subtree is skipped
const Text('Loading')

// Applies to everything that does not depend on variable data
const SizedBox(height: 16)
const Divider()
const Icon(Icons.star)

The reason it works is identity: when comparing the old widget with the new one, Flutter first checks whether they are the same object. With const they are, because the compiler creates a single shared instance, and the answer arrives without examining the children. Without const, Text('Loading') is a new object on every build(), formally equal but not identical.

The limit is that const applies only if all the arguments are compile-time constants: a Text(titolo) with a variable titolo cannot be const, and no trick makes it so. The single gain is small; it counts because it applies in hundreds of places and because it costs one word.

2. RepaintBoundary: isolating what moves

An animation repaints the layer that contains it. If that layer is the whole page, every frame repaints the whole page, even if only a little circle changes.

An animated indicator inside a boundary of its own
class Pulsante extends StatelessWidget {
  const Pulsante({required this.progress, super.key});
  final Animation<double> progress;

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        const Text('Loading'),
        RepaintBoundary(
          child: AnimatedBuilder(
            animation: progress,
            builder: (context, _) =>
                CircularProgressIndicator(value: progress.value),
          ),
        ),
      ],
    );
  }
}

RepaintBoundary tells the engine to put its subtree in a separate layer. From that moment the repaint caused by the animation stops at the boundary, and the Text next to it is not touched. Remove it, and the article above stays valid but the work per frame is that of the whole Row and of whatever contains it.

The pair AnimatedBuilder plus RepaintBoundary is the correct way to write this: AnimatedBuilder limits the rebuild to the builder function alone, RepaintBoundary limits the repaint to the layer. They are two different things, and you need both.

It should not be added out of habit, though: every boundary is one more layer to composite, so scattering many of them over a large tree makes the raster thread's work worse. You put one where something animates inside a container that does not - which is exactly the case above.

3. Images: decode at the display size

A 3000x2000 photo shown in a 96-pixel box takes up in memory the space of the photo, not of the box. In a list of fifty rows this is the biggest performance problem you will meet, and it is not on the raster thread: it is memory.

cacheWidth and cacheHeight, tuned to the screen density
class Copertina extends StatelessWidget {
  const Copertina({required this.url, super.key});
  final String url;

  @override
  Widget build(BuildContext context) {
    final dpr = MediaQuery.devicePixelRatioOf(context);
    return Image.network(
      url,
      width: 96,
      height: 96,
      cacheWidth: (96 * dpr).round(),
      cacheHeight: (96 * dpr).round(),
      fit: BoxFit.cover,
    );
  }
}

width and height decide how much space the widget occupies on screen; cacheWidth and cacheHeight decide at what size the image is decoded, that is how much memory it takes. They are two distinct things, and setting only the first two is the common mistake: the image appears small and in memory it stays enormous.

The multiplication by devicePixelRatioOf(context) is the part you cannot skip. On a screen with ratio 3, a 96-logical-point box is 288 physical pixels: passing cacheWidth: 96 the image is decoded at 96 pixels and then enlarged, and it looks blurry. By multiplying you get the exact size and no waste.

The trade-off to know: Flutter's image cache takes the decode size into account, so the same URL requested with different cacheWidth values is decoded several times. In a screen that shows the same image as a thumbnail and full screen, it pays to choose two fixed sizes rather than adapt it to every container.

4. Lists: declare the height when you know it

ListView.builder builds only the visible rows, and that is the bulk of the work. One thing remains that you can take off its hands: the computation of where each row begins.

itemExtent: layout becomes a multiplication
class ListaFissa extends StatelessWidget {
  const ListaFissa({required this.titoli, super.key});
  final List<String> titoli;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemExtent: 72,
      itemCount: titoli.length,
      itemBuilder: (context, i) => ListTile(title: Text(titoli[i])),
    );
  }
}

With itemExtent: 72 you declare that every row is 72 points tall. Flutter no longer has to measure the rows to know where the scroll position is: it computes it as index * 72. The gain is felt above all when you jump to a distant point of the list or when you scroll fast, because without this information the list has to estimate and then correct itself.

The condition is that the height is really that: if a row turns out taller, it is clipped. When the rows have uniform height but you do not know it in advance there is prototypeItem, which receives a sample element: Flutter measures it once and uses that measurement for all of them. And if the heights vary in a predictable way there is itemExtentBuilder, which computes it per index.

The three parameters are alternatives, not cumulative, and the choice is driven by what you know: itemExtent if you have a number, prototypeItem if you have a sample widget, itemExtentBuilder if you have a function. If you are in none of the three cases, let Flutter measure - it is correct anyway.

The checklist, and how to order it

Before considering a performance problem closed

  • Measured in --profile, not in debug
  • Identified which thread overruns, UI or raster, before changing code
  • const on all widgets without variable data
  • RepaintBoundary only around what animates
  • cacheWidth and cacheHeight multiplied by the pixel ratio
  • Row height declared in lists, when it is uniform
  • Tried on a slow device, not only on yours
  • Checked that the web build, if there is one, still uses Skia

The first two items are about method and really do come first: changing code without knowing which thread is late is guessing, and half the time you optimize the wrong side. The four in the middle are the fixes, in order of increasing cost. The seventh is the one that changes the verdict most often, because your phone is almost always faster than your user's - and on a device below Android API 29 the renderer changes too.

What you can do now

You can compute the frame budget from the screen refresh rate, read buildDuration and rasterDuration to know who overruns, and apply the four fixes knowing which problem each one solves. You also know where Impeller is active and where it is not, which is the information that spares you from hunting for shader jank on a platform that no longer has it.

On the rebuild front, the granularity is decided by state management: how to limit a rebuild to the single field that changed is in Riverpod in depth. If you want to understand why const and repaint boundaries work, the mechanism underneath - widget, element and render object - is in Flutter internals. Animations, which are where the budget is spent, have an article of their own: implicit animations, physics and custom painters. To turn a measurement into a repeatable check, instead, see integration testing and DevTools. If the events of a Bloc cause too many rebuilds, the case is in BLoC in depth; to see the same rendering in the browser, look at Flutter Web with WebAssembly.

Sources

  • Flutter - Impeller rendering engine - release 3.27 as the default for iOS and Android API 29+, iOS with no way back to Skia, the fallback to OpenGL below API 29 or without Vulkan, the web still on Skia, macOS and Windows from 3.47, and the correct form of the --no-enable-impeller flag. Consulted on 2026-11-08.
  • Flutter API - FrameTiming - the fields buildDuration, rasterDuration, totalSpan and vsyncOverhead. Consulted on 2026-11-08.
  • Flutter API - SchedulerBinding.addTimingsCallback - the batched delivery of the timings of completed frames, and the symmetric removal callback. Consulted on 2026-11-08.
  • Flutter API - ListView.builder - the existence and mutual exclusivity of itemExtent, prototypeItem and itemExtentBuilder. Consulted on 2026-11-08.
  • Flutter - Performance profiling - the reason you measure in profile mode and the reading of the two overlay bands. Consulted on 2026-11-08.
  • Code verification - the Dart blocks were analyzed with flutter analyze on Flutter 3.44.2 stable (revision c9a6c48423) on 2026-11-08, result "No issues found!". No execution on a device: the machine has no emulators configured.

The first five are the project's documentation and API reference, and that is where all the statements about versions, flags and parameter names come from - not from third-party articles, which are precisely the route by which "3.10" and "--disable-impeller" spread. The last entry declares the limit of this article: the code is verified as correct, not as fast. Performance is measured on your device, and the only number that counts is the one you read yourself.

In this series, the next article is Platform Channels: Integrating Swift and Kotlin Native Code.

Commenti

Caricamento commenti...

Sign in to comment

New articles and tools on Telegram too

The Telegram channel flags the site's new articles and tools.

Did you like this article?

Explore other content on the blog or discover my projects