Caching and snapshot churn

I wanted to know whether caching pays off when only a few cards in a 24-card canvas dashboard change each frame. This page pits full drawElementImage() replay against a main-thread captureElementImage() cache, a plain offscreen 2D canvas per card, and a clipped dirty-rect redraw using nine-argument drawElementImage(). Below that, a separate test churns ElementImage snapshots at 60 fps and watches frame time and memory.

Idle. The 24 cards above are drawn once on load with zero open snapshots. Pick a strategy or press Run full sweep to time your device.

Strategy Dirty rAF p50 rAF p95 Paint JS LoAF (>50 ms / post-main) Snapshots (made / peak / end) Canvas MB
Not run yet. Press Run selected or Run full sweep above.
Show the code the four partial-update strategies
  1. Full replay. Resets the canvas and replays five-argument drawElementImage() for all 24 cards every frame.
  2. Main-thread captureElementImage() cache. Re-captures only cards in e.changedElements or marked dirty, closing the old snapshot before capturing the replacement so open snapshots stay at or below 24.
  3. Plain offscreen 2D canvas cache. Draws dirty cards once and copies each dirty card into a plain non-drawable <canvas>; clean cards blit with ctx.drawImage().
  4. Clipped dirty-rect + nine-argument source-rect draw. Keeps the existing canvas pixels, clips to the mutating metric strip of each dirty card, and updates it with nine-argument drawElementImage().

Snapshot churn at 60 fps

Taking an ElementImage snapshot on a timer and forgetting to call close() holds GPU memory until garbage collection. This test measures the other case: taking snapshots at 60/s (and 240/s at 4 cards per frame) and closing every one either straight away inside the same paint handler or in batches of 8, against a direct drawElementImage() baseline.

Not run yet. Every snapshot created during the test is closed before the mode finishes.

Churn mode rAF p50 rAF p95 Paint JS Capture + close LoAF (>50 ms / post-main) Snapshots (made / peak / end) Canvas MB
Not run yet. Press Run churn test above.
Show the code 60 fps snapshot churn and pool teardown
  1. Churn loop. Captures 1 or 4 cards per frame inside paint, draws the snapshot, and either calls close() straight away or drains a pool of 8 every eighth frame.

How it works

Live checks

Each check runs on its own tiny fixture on the hidden test stage and closes every snapshot and canvas when it finishes.

ResultCheckDetail

Findings