# gpucanvas: 5,000 Live React Screens on a WebGPU Infinite Canvas

> Source: <https://dev.to/berkantay/gpucanvas-5000-live-react-screens-on-a-webgpu-infinite-canvas-2h6l>
> Published: 2026-11-18 11:32:29+00:00

**Key takeaway:** Batching DOM elements into 2048px pages and a texture-array atlas, redrawing only dirty pages via MutationObserver, took 5,000 live React screens from 18–20 fps to 113–115 fps by cutting drawElementImageToTexture calls to one per page.

*Originally published on [berkant.me](https://berkant.me/blog/gpucanvas-webgpu-infinite-canvas).*

[gpucanvas](https://github.com/berkantay/gpucanvas) is an open-source TypeScript library that puts thousands of live DOM nodes on an infinite canvas. The GPU draws them. An editor selects, moves and resizes them. WGSL shaders and transitions run on them. An AI agent can read them and point at them.

The nodes stay real DOM. React state, events, CSS and accessibility work as usual. Click a screen and type into it: the click and the keystrokes go to the real element.

*The same session on both sides: 5,000 live React screens, the same camera path, a message typed and sent. Left, plain DOM under a CSS transform. Right, gpucanvas. Chrome on a MacBook Pro, frame rates measured live. [Watch the video on berkant.me](https://berkant.me/blog/gpucanvas-webgpu-infinite-canvas).*

In the 30-second benchmark tour at 5,000 screens, gpucanvas runs at **113 to 115 fps and plain DOM at 18 to 20 fps**. In a longer tour at 10,000 screens, it is 108 fps against 9.

```
npm install gpucanvas
js
import { GpuCanvas, CanvasNode } from "gpucanvas/react";

<GpuCanvas style={{ width: "100vw", height: "100vh" }}>
  {cards.map((card) => (
    <CanvasNode key={card.id} x={card.x} y={card.y} width={240} height={150}>
      <Card {...card} />
    </CanvasNode>
  ))}
</GpuCanvas>;
```

There are two usual ways to put real HTML on an infinite canvas, and each gives something up.

**Plain DOM:** camera moves → CSS transform on one container → the browser repaints every visible element.

**Draw it yourself:** camera moves → redraw everything in a canvas → fast, but no inputs, focus, CSS or React.

The first is fine for a hundred cards. With a few thousand full app screens, each a tree of real elements, the frame budget is gone. That is the left side of the video above. The second is fast, but you end up rebuilding a browser inside the browser.

gpucanvas takes both: the elements stay in the DOM, and the GPU draws their pixels.

Chrome 157 implements [HTML-in-Canvas](https://github.com/WICG/html-in-canvas), a WICG proposal that lets a `<canvas>` hold live DOM children and draw them. Two pieces matter here:

`<canvas content="drawable">` keeps its children as real, laid-out, interactive elements.`GPUQueue.drawElementImageToTexture()` rasterizes one of those elements straight into a WebGPU texture.
The DOM stays the source of truth, and WebGPU gets a texture of each element to draw however it wants.

It is on by default in Chrome 157 and later on a computer. On older Chrome, turn on `chrome://flags/#canvas-draw-element` and relaunch. Without it, gpucanvas falls back to a CSS-transformed container with the same API, and the demo runs 1,000 screens and says so.

Calling `drawElementImageToTexture` once per element per frame would be far too slow. Each call allocates and fully rasterizes, and Chrome manages about 250 to 550 of them per second in total. Most of gpucanvas is about calling it as rarely as possible.

**The pipeline:** live DOM nodes → pages of 2048 px (one call per page) → texture-array atlas → cull to the view → one instanced draw call. A `MutationObserver` sends changed nodes back through a page; rasterized pages are parked with `content-visibility: hidden`.

`drawable`. In the next paint event it is drawn into the atlas, whole, or one node at a time when only a few changed. Then it is parked with `content-visibility: hidden`, which keeps layout but skips paint. The browser spends nothing on it per frame.`MutationObserver` marks a node dirty when its content changes. Loading images, web fonts and CSS transitions trigger a redraw too.
The pixels on screen come from the GPU, but input has to land on the DOM.

**Input:** pointer or tap → only the page under it is registered for hit testing → Chrome hit tests it where the GPU drew it → the real element gets the click, the typing, the hover.

Touch has no hover, so a tap makes the node under the finger live and hands the click to the element it landed on. A two-finger pinch zooms and pans the camera. A focused node keeps its page live.

Building this meant finding where Chrome's implementation differs from the [WICG explainer](https://github.com/WICG/html-in-canvas). If you are building on HTML-in-Canvas, these will save you time:

`canvas.updateElementGeometry(el, options)` registers it.`canvasTransform`.` options.canvasTransform`, a matrix in CSS pixels from the element's border box to the canvas. Chrome 156 ignored it and hit tested at the CSS box, positioned with `el.style.transform = canvas.getElementTransform(el, drawMatrix)`. gpucanvas handles both.` changedElements`. Their snapshot is available from the next paint event.` requestPaint`. 10,000 always-drawable nodes run at 22 fps even when idle, which is why pages get parked.
Once every node is a texture on the GPU, a lot comes cheap.

*Marks from an agent, a wipe and a dissolve, the glass lens and shockwaves, all on live components.*

**Editor.** `bindEditor` turns the canvas into a design-tool editor. Click to select, double-click to go a layer deeper, down to any element or React component. Move and resize with snapping guides. The GPU draws the selection outlines, 2 CSS pixels wide at any zoom.

**Shader effects.** Run WGSL on live components: a glass lens, frost, shockwaves, glitch, VHS, or your own. An effect is a function over the node's pixels:

``` js
import { defineEffect } from "gpucanvas";

const scanlines = defineEffect({
  name: "scanlines",
  animated: true,
  params: [3],
  wgsl: /* wgsl */ `
    fn effect(input: EffectInput) -> vec4f {
      let color = source(input.uv);
      let y = input.uv.y * input.size.y + input.time * 20.0;
      return color * (0.85 + 0.15 * step(0.5, fract(y / input.params.x)));
    }`,
});

canvas.setEffect(node, scanlines);
```

Effects draw from each node's snapshot in the same pass. With an effect on every one of the 5,000 screens, most cost nothing measurable. Glass, the heaviest, costs about 12%.

**Snapshots.** Every node is already on the GPU, so its pixels are one call away, with no headless browser: `canvas.snapshot(node)` returns `ImageData`, `diffImages` shows what changed between two versions, and `recordFilmstrip` keeps a history.

**Agent view.** An AI agent reads the canvas the way a person sees it.

**Agent view:** canvas → `describe` → a JSON tree with ids, roles, text and rects → the agent can `capture` an image of any element or region, and point with arrows, pins, notes and cursors.

A sign-in screen comes back as about 35 entries and 3.5 KB of JSON, read in 3 ms. The agent can capture any element or region as an image, and point at things with marks that follow the camera.

**Transitions.** Dissolve, wipe or fade one node out and another in on the GPU, while both stay live.

Measured on an M-series Mac, Chrome 157, 1600 × 900 window, DPR 1. The tour is a 94-second session from the overview into clusters of app screens, close-ups up to 500% zoom, 20 clicks and typed messages, then back out.

| Screens | gpucanvas avg | gpucanvas p95 | DOM avg | DOM p95 | 
|---|---|---|---|---|
| 5,000 | 117 fps | 9.2 ms | 23 fps | 50.2 ms | 
| 10,000 | 108 fps | 16.7 ms | 9 fps | 133.8 ms | 

DOM is the same screens in one CSS-transformed container, which is also gpucanvas's fallback. Press `b` in the [demo](https://berkantay.github.io/gpucanvas/) to run the benchmark yourself.

**Does gpucanvas work without WebGPU?** Yes. Where WebGPU and HTML-in-Canvas are missing, it falls back to a CSS-transformed DOM container with the same API. Effects with a CSS look become CSS filters there.

**Which browsers run the GPU path?** Chrome 157 or later on a computer, where HTML-in-Canvas is on by default. Firefox, Safari, and iPhone and iPad browsers have no HTML-in-Canvas yet, so they run the DOM version. Since 0.5, `snapshot` works there too with a `snapshotFallback`.

**Is it only for React?** No. The core API takes plain DOM elements. `gpucanvas/react` adds `<GpuCanvas>`, `<CanvasNode>`, `useEditor` and a component picker.

**Is it ready for production?** It is early, version 0.5, and the API can still change. Two known gaps: Tab skips nodes on parked pages, so moving focus across pages needs a focus model, and compositing does not run in a worker yet.

**What license?** MIT.
