On this page

10. What are the limitations of the Virtual DOM?

📄 Notesmedium#virtual-dom#performance#trade-offs

Short answer

The Virtual DOM adds CPU and memory overhead (recreating elements, running components, diffing, keeping fiber trees), and by default re-renders whole subtrees even when only a tiny value changed. Its heuristics can't detect cross-parent moves and depend on correct keys. It doesn't help with expensive DOM work like layout thrashing or huge node counts, and it can't speed up a single slow component. Most fixes require manual or compiler-driven memoization.

Explanation

Main limitations

LimitationImpactMitigation
Diffing overheadExtra JS work before every DOM writememo, React Compiler, state colocation
Coarse-grained updatesA state change re-renders all descendantsMove state down, children-as-props, split context
MemoryElement objects per render + two fiber treesUsually fine; avoid giant trees
Heuristic diffNo cross-parent move detection; type change rebuilds subtreeKeep structure stable; use keys
Key dependenceBad keys → wrong state or remountsStable unique ids
Doesn't fix DOM costsLayout, paint, too many nodes still slowVirtualization, CSS containment, transform animations
Can't split one componentA 200 ms render blocks even in concurrent modeBreak up work, memoize, move to a worker
High-frequency updates60 fps state updates are costlyRefs, CSS/Web Animations, animation libraries
Third-party DOM librariesThey mutate DOM React doesn't know aboutIsolate them behind a ref + effect

Analogy: a delivery service that always re-checks every package on the truck before dropping off one parcel. Reliable, but wasteful when you know exactly which parcel changed.

Coarse-grained vs fine-grained

React (VDOM):   count changes -> re-run Component (and children) -> diff -> 1 text update
Signals:        count changes -> directly update the 1 text node bound to count

This is why frameworks like Solid and Svelte 5 (runes) skip the Virtual DOM, and why React invested in the React Compiler (stable since 2025) to automatically memoize components and values.

Example

import { useState, memo } from "react";

// Limitation: typing re-renders the whole expensive table
function SlowPage({ rows }) {
  const [text, setText] = useState("");
  return (
    <>
      <input value={text} onChange={(e) => setText(e.target.value)} />
      <BigTable rows={rows} />
    </>
  );
}

// Mitigation 1: memoize the expensive child
const BigTable = memo(function BigTable({ rows }) {
  return (
    <table>
      <tbody>
        {rows.map((r) => (
          <tr key={r.id}><td>{r.name}</td></tr>
        ))}
      </tbody>
    </table>
  );
});

// Mitigation 2: colocate state so only the input re-renders
function SearchInput() {
  const [text, setText] = useState("");
  return <input value={text} onChange={(e) => setText(e.target.value)} />;
}

export default function FastPage({ rows }) {
  return (
    <>
      <SearchInput />
      <BigTable rows={rows} />
    </>
  );
}

Common mistakes

  • Wrapping everything in memo/useMemo without profiling; memoization itself has a cost and adds complexity.
  • Blaming the Virtual DOM for slowness caused by rendering 10,000 DOM rows.
  • Using context for rapidly changing values, which re-renders every consumer.

Follow-up questions

  • Does the React Compiler remove the Virtual DOM? No. It reduces how often components and elements are recreated, but reconciliation still happens.
  • How do you find the bottleneck? React DevTools Profiler for render cost, the browser Performance panel for layout/paint.
  • When is the Virtual DOM a good fit anyway? Most app UIs, where developer productivity and predictable code matter more than micro-benchmarks.

Quick recap

  • Extra CPU and memory overhead.
  • Coarse-grained re-renders by default.
  • Heuristic diff and key dependence.
  • Doesn't fix DOM-heavy or single-component bottlenecks.
  • Mitigate with colocation, memoization, React Compiler and virtualization.