Skip to the page

Performance · senior

List virtualisation

Virtualisation renders only the rows visible in the viewport (plus a small overscan) inside a container sized for the full list, so 10,000 rows cost about as much DOM as 20.

The notes

What you must know

  • The cost of 10k rows is the DOM size and layout, not React itself; memo on rows does not fix it.
  • Math for fixed height: start = floor(scrollTop / rowHeight), end = ceil((scrollTop + viewportHeight) / rowHeight) - 1, add overscan, clamp to the list; a spacer of itemCount * rowHeight keeps the scrollbar correct; visible rows are offset by start * rowHeight.
  • Variable heights: estimate, measure rendered rows (ResizeObserver), cache measured sizes, and correct the scroll offset so content does not jump.
  • Libraries: TanStack Virtual, react-window, react-virtuoso. In React Native, FlatList/FlashList do this.
  • Combine with pagination or cursor-based infinite loading; keep the total DOM size bounded.
  • Trade-offs: browser find-in-page cannot find unrendered rows, screen readers see fewer rows (use aria-rowcount/aria-rowindex for grids), SEO for server-rendered lists.
  • Lighter alternative for medium lists: CSS content-visibility: auto with contain-intrinsic-size.

The red pen

Common traps: mistake → fix

  • Mistake: "Just memo the rows"

    Fix: the DOM is still huge.

  • Mistake: "Lazy-load the images and it is fixed"

    Fix: the DOM and layout cost stay.

  • Mistake: "Virtualisation has no downsides"

    Fix: find-in-page, accessibility and scroll restoration need work.

Easy to hard

Questions interviewers ask, easy to hard

  1. We render a 12,000-row table and scrolling stutters. What do you do?
  2. How does windowing work: overscan, spacer height, offsets?
  3. Rows have variable heights. Now what?
  4. What about Ctrl+F, accessibility and scroll restoration?
  5. Pagination vs infinite scroll vs virtualisation: when each?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview