One canvas vs many

I wanted to know whether it's better to pack lots of live interactive controls into one shared canvas or give each control its own canvas and evict the offscreen ones. Pick an architecture and a control count below to measure mount time, bulk theme-switch jank, scroll smoothness and estimated GPU memory on your device.

Active: 1. Shared 2D (N=8) Canvases: 1 Est. canvas: 0.0 MB Largest: 0.00 MP Budget cap: 3.6 MP / 80 MB

Mounted Architecture 1 with 8 controls. Press a measurement button or Run full comparison.

Architecture N Mount (ms) Peak canvas MB WebGL tex MB Theme wall (ms) Missed frames Worst rAF (ms) Scroll FPS (p50 / p95-tail) LoAFs (max ms)
No completed sweep rows yet. Press a test button or Run full comparison.

Scroll FPS p95-tail is 1000 divided by the 95th-percentile frame duration, so a lower number shows tail frame stalls. Peak canvas MB comes from window.__gfx.memory(). For Architecture 2, WebGL tex MB estimates the RGBA8 textures held inside ElementGL on top of the canvas swapchain.

Show the code layout budget, the four architectures and the timing loops
  1. Grid layout, 3.6 MP band splitting and the 80 MB DPR cap. Keeps every single canvas under 4 megapixels and total backing stores under 96 MB at phone scale.
  2. Architecture 1: one shared 2D canvas. Draws each control with a 5-argument drawElementImage() call and splits into vertical bands only when one canvas would exceed the pixel cap.
  3. Architecture 2: one shared WebGL canvas via ElementGL. Uploads dirty controls with texElementSubImage2D(), draws visible quads inside a sticky viewport canvas and syncs hit boxes with updateElementGeometry().
  4. Architecture 3: N live per-element 2D canvases. One drawable canvas per control, all backing stores kept allocated even when scrolled out of sight.
  5. Architecture 4: IntersectionObserver 0x0 eviction and ~6 ms frame-budgeted painting. Zeroes offscreen canvases and spreads dirty repaints across frames using a moving average of paint cost.
  6. Bulk theme switch, internal-container scroll pass and LoAF tracking. Measures completion wall time, missed 60 Hz frames, worst rAF gap and Long Animation Frames without scrolling the page itself.

How it works

Every architecture mounts the same interactive HTML controls (each has a checkbox, a counter button and a range slider) inside a 340 px tall internal scroll container. On load, the page starts in Architecture 1 with 8 controls so opening the page allocates one small 2D canvas and runs no background loop. Whenever you switch architecture or finish a sweep row, every discarded canvas is zeroed, removed from the DOM and passed to window.__gfx.retire().

Architecture 1 puts all controls inside one <canvas content="drawable" layoutsubtree> when the full grid fits under 3.6 megapixels. At 64 or 128 controls on a high-density screen (like a 412 px Android phone at scale 2.625), one tall canvas would cross the 4 megapixel guard limit, so the layout splits vertically into the minimum number of stacked band canvases.

Architecture 2 opens a single WebGL 2 context through new ElementGL() from /lib/element-gl.js on one sticky viewport-sized canvas. All N controls stay children of that canvas. Dirty controls upload with gl.texElementSubImage2D(), visible rows draw through a fragment shader, hit boxes follow scroll via updateElementGeometry() (with a dataset.hitTick toggle to clear Chromium's hit-test cache), and offscreen children get inert = true so Tab focus skips them.

Architecture 3 mirrors a naive custom-element approach: one drawable 2D canvas per control, all backing stores kept live in GPU memory. Architecture 4 keeps the same per-element DOM grid, adds an IntersectionObserver rooted on the internal scroll box to set offscreen canvases to 0x0, and routes dirty visible canvases through a requestAnimationFrame scheduler that aims for a 6 ms paint budget per frame. Because requestPaint() defers actual painting until the browser's rendering phase later in the same frame, the scheduler tracks an exponential moving average of each canvas's paint handler duration instead of only timing the requestPaint() calls.

Live checks

Findings