Quick answer: Eliminate per-frame allocations by reusing object pools and preallocated typed arrays, and avoid creating closures or temporary arrays inside the render loop.

Your canvas game is buttery on a laptop but on an iPhone it freezes for a few milliseconds every couple of seconds. Those are GC pauses, and they trace back to garbage you create every frame. Stop allocating in the loop and they disappear.

How to fix it

1. Pool your transient objects

Reuse vectors, particles, and event objects from a pre-sized pool instead of constructing new ones each frame. Fewer allocations means the collector runs less often and stalls less.

2. Avoid hidden allocations

Array methods like map, filter, and spread create new arrays; replace them with index loops in hot paths, and hoist closures out of the frame callback.

3. Measure with the timeline

Record a performance trace in Safari's Web Inspector and look for sawtooth heap growth and GC markers aligned with the hitches to confirm allocation is the cause.

Catching the ones you can't reproduce

The hardest version of this to fix is the one you can't reproduce — it only happens on a player's hardware, OS, driver, or save state, under conditions that simply aren't present on your machine. A report that says “it crashed” or “it froze” gives you nothing to act on, so the bug survives release after release while quietly costing you players.

Automatic error capture closes that gap. Each failure arrives with its full stack trace, the device and OS, the build number, and a breadcrumb trail of what the player did right before it broke, so even a failure you have never seen becomes a specific, reproducible issue. Fold identical failures into one signature ranked by how many players each hits, and your worklist sorts itself worst-first instead of arriving as a stream of vague complaints.

This is where a tool like Bugnet earns its place. Its SDK captures every HTML5 error automatically with the full stack trace plus device, OS, memory, build, and game-state context, folds duplicates into one grouped issue with an occurrence count, and ties each to the build it first appeared on — so you fix the problem that hurts the most players first and confirm it is gone when its signature disappears from the next release.

Reproduce it once with full context and the fix writes itself. The hunt is the expensive part.