Skip to content

Glossary · Rendering

Web Worker Layout

Also known as: Off-Main-Thread Layout.

Running graph layout computation in a Web Worker so the main UI thread stays responsive even for graphs with thousands of nodes.

Force-directed and dagre layouts are iterative algorithms that can take hundreds of milliseconds — sometimes seconds — to converge on large graphs. Running them on the main thread blocks every other interaction: scrolling jitters, buttons stop responding, and the page feels frozen.

A Web Worker is a browser-managed background thread that runs JavaScript in parallel with the main thread. By moving layout computation into a worker, the UI thread continues to handle user input and rendering at 60fps while the layout runs in the background. The worker posts incremental position updates back to the main thread via `postMessage`, and the renderer applies them on the next animation frame.

TopoKit ships a built-in worker layout runner: `import { workerLayoutRunner } from "@topokit/layouts/worker"` and pass it as `layoutRunner`. No build configuration required.