Flutter / Flame canvas rendering performance facts
flutterflameimpellercanvaskitwebperformancedraw-calls
Research-backed numbers and engine quirks for 2D games drawn with Flutter's Canvas through the Flame
engine, gathered for the Flutter build of Spacebar (archived 2026-08-07 in favor of vanilla JS, but the
facts still apply to any Flutter canvas work).
Budgets and costs
- About 200 draw calls per frame is the Impeller CPU budget on mid-range hardware (Pixel 6 Pro class). The bottleneck is CPU-side geometry processing, not the GPU.
- Switching Paint properties between draw calls is free: no batching penalty for different colors or styles.
drawRectis the cheapest primitive, cheaper thandrawPathordrawCircle.MaskFilter.blurcosts about 2 to 4 ms per object: the single most expensive Paint property. Ban it from anything drawn many times.- Radial gradients are GPU-evaluated, "medium" cost: budget roughly 5 to 10 visible per frame.
toImageSync()takes under 1 ms and produces a GPU-resident texture; prefer it overtoImage(), which has a 5 to 10 ms CPU readback on the web. Use it (viaPictureRecorder) as an escape hatch to cache a static background if draw calls ever become the bottleneck.drawAtlasis broken on web (CanvasKit), which rules out atlas batching for web-targeted games.- WebGL
MAX_TEXTURE_SIZE: 2048 is safe everywhere, 4096 covers about 99% of GPUs. - Flame supports camera-level fragment-shader post-processing chains, so scanlines, bloom and vignette can be one GPU pass instead of many draw calls.
Flame performance checklist (from Run, 2026-03 research and 2026-07 fixes)
Gathered for Run, Justin's Flutter/Flame speedrun platformer (run memory: research-performance.md,
speedrun-platformer.md, improvement-cycles.md).
- Profile in profile mode: flutter run --profile. Debug builds are 2 to 5x slower and
misleading. In the performance overlay the top graph is raster/GPU, the bottom is UI/Dart, the
white line is 16 ms. checkerboardOffscreenLayers shows expensive saveLayer() calls.
- Frame budget: 60 fps is about 16 ms (roughly 8 ms UI + 8 ms raster). flutter_displaymode
unlocks 90/120 Hz on Android; leave headroom for thermals.
- Broadphase: Flame's default sweep-and-prune is fine under ~100 collidables. Above that use
HasQuadTreeCollisionDetection with initializeCollisionDetection(mapDimensions:,
minimumDistance: 10), implement onComponentTypeCheck() to skip impossible pairs (results are
cached), and call QuadTree.optimize() at idle moments.
- Collision types: mark static tiles passive and only the player and moving entities
active (and remember passive-passive pairs are never tested, see Flame engine architecture and gotchas).
- Pooling: reuse frequently spawned objects (particles, projectiles, rebuilt items) via
Flame's ComponentPool (Flame 1.36) or a simple acquire/release list, to avoid GC stutter.
- Atlases: SpriteBatch draws many regions of one atlas in a single call (but see the
drawAtlas-on-web caveat above). Atlas limits 4096 on web, 8192 native; add margins or
extrusion to sprite edges or float rounding shows seam lines.
- Memory: Game.images is game-scoped and freed with the game; Flame.images is global.
GPU textures need explicit release; Dart GC alone does not free them. Preload the next level's
assets before its countdown.
- Culling: camera.visibleWorldRect and camera.canSee(component) let off-screen components
skip work.
- Impeller (default on iOS, and on Android API 29+ with Vulkan) removes shader-compilation jank
and rasterizes much faster; it does not exist on Flutter web, which still uses CanvasKit/Skia.
- Widget-level jank: avoid the Opacity widget and Clip.antiAliasWithSaveLayer, use
RepaintBoundary selectively (it costs GPU memory), prefer const constructors.
- Cache render objects keyed on what they depend on: Run's 2026-07 frame-spike pass cached
paints, gradient shaders, icon TextPainters and sprites per component, and throttled the
on-screen run timer's text relayout to 30 Hz (a stopped timer always shows the exact value).
- Getter traps: a Dart getter that rebuilds data on every access is invisible at the call
site. Run's builtinThemes getter rebuilt 134 pixel-art grids each time it was read (inside
loops during level load); a lazy final was a one-line fix.
- Audio stutter is often a frame-time problem: see Game audio in Flutter with flutter_soloud.
Engine gotchas
Flame API and Riverpod-integration gotchas from the same project (provider writes during
update(), missing exports, hitbox constructors) are collected in Flame engine architecture and gotchas.
Why Spacebar left Flutter
The game was effectively web-only, mobile web was unplayable, and the build and deploy cycle was slow compared with editing a JS file and refreshing. The JS rebuild uses Canvas2D with no build step; see Caching static sites and unbundled ES modules (?v= stamps, no-cache, prefetch).
See also
- Zero-allocation render and update loops
- Neon glow without blur and 2D ground-coverage tricks
- Flame engine architecture and gotchas
- Visual effects in Flame (particles, effects, decorators, shaders)
- Flutter web (renderers, SEO, performance, when not to use it)
Linked from
- 2D tile-based liquid simulation (cellular automata)
- Flame engine architecture and gotchas
- Game audio in Flutter with flutter_soloud
- Neon glow without blur and 2D ground-coverage tricks
- Rendering a tile map without a chunk cache
- Visual effects in Flame (particles, effects, decorators, shaders)
- Zero-allocation render and update loops