Skip to content
Back to blog
Performance6 minute read

Rendering 100k Trace Spans at 60fps with 2D Canvas

Moving heavy timeline views off the DOM, culling invisible rectangles, and staying razor sharp on Retina screens.

ASRaka Mahendra
  • Performance
  • Canvas
  • Rendering
Cover art for “Rendering 100k Trace Spans at 60fps with 2D Canvas”

Rendering thousands of deeply nested span bars as DOM nodes triggers expensive layout recalculations whenever the user zooms or pans. Switching the timeline viewport to HTML5 Canvas eliminates DOM churn completely.

1. Merge sub-pixel spans before drawing

When zoomed out, dozens of 0.2px spans map to the same horizontal pixel column. Merging adjacent sub-pixel spans into a single bucket keeps draw calls under 1,500 per frame regardless of trace size.

2. Viewport culling and Retina DPR scaling

Binary-search your sorted span intervals so only rows intersecting the visible time window reach the draw loop, and scale the backing canvas by devicePixelRatio with pixel-snapped coordinates for crisp labels.

3. Fast spatial hit-testing on hover

Because Canvas does not maintain DOM hover targets, bucket spans by depth row so pointermove hit-testing resolves in O(log n) time and updates tooltips without triggering full React re-renders.

Copied