📚 Encyclopedia

Games & Graphics · updated 2026-10-13

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

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

Linked from

Sources: run memory (research-performance.md, improvement-cycles.md), spacebar memory (feedback_perf_patterns, feedback_fps_forever, project_game_overview, project_improvement_cycles), research/rendering_performance_flame.md