📚 Encyclopedia

Games & Graphics · updated 2026-10-13

Zero-allocation render and update loops

performancegarbage-collectionflutterflamecanvasjavascriptgame-loop

The most common cause of frame drops (jank) in a hand-written 2D game is not drawing too much; it is creating short-lived objects inside render() or update(). Every frame at 60 FPS that allocates a few hundred Paint, TextPainter, Vector2 or {x, y} objects builds garbage-collector pressure that shows up as periodic stutter, worst on the web. In the Spacebar project the same bug was "fixed" in sessions 3, 5 and 7 and kept coming back in every new component, so it is worth treating as a standing rule, not a one-time cleanup.

The rule

Review checklist before committing a component

  1. Read every render() / update() (or rAF callback) for new, constructors, object literals, array literals, .map() / .filter(), string concatenation, and closures.
  2. Check debug overlays too: in Spacebar a debug overlay was always visible in production and allocated paragraphs every frame. Gate debug UI behind a flag (F3) and cache its text.
  3. Count draw calls across all systems against a budget (see Flutter / Flame canvas rendering performance facts).

Measuring, not guessing

Gotchas

See also

Linked from

Sources: spacebar memory (feedback_perf_patterns, project_improvement_cycles, project_js_rebuild)