IT lexicon › Web › Virtual DOM diffing

Virtual DOM diffing

Web På svenska → Updated: 2026-05-30

The technique (popularized by React) where the UI is described as a lightweight "virtual" DOM tree in memory; on a change a new tree is built and compared (diffed) against the old one, so that only the actual differences are applied to the real (expensive) DOM. Also called reconciliation.

Why: touching the real DOM is expensive, and manually keeping track of exactly what should update is error-prone. React's solution: re-render the component to a new virtual tree on every change, compare with the previous one, and compute the minimal set of real DOM operations. "Keys" (key) help the diff algorithm match elements in lists efficiently. Trade-off: the diffing is work in itself — for large/frequently updated trees it can become a bottleneck (React Fiber introduced time-slicing so as not to block the main thread). The modern counter-argument: signals and compiler-based frameworks (Svelte) skip the virtual DOM entirely and update exactly what changed directly → often faster. Diffing vs signals is a central frontend debate. A defining technique of the 2010s frameworks. Related to signals and hydration.

← Back to the lexicon