List virtualization budget
Decide when windowing is worth its complexity, using node counts and a measured frame budget.
- #react
- #performance
- #virtualization
Windowing costs real complexity. It breaks Ctrl+F, it makes accessibility harder, and it introduces scroll anchoring bugs. This entry is the threshold test for paying that.
Node budget
A working budget for a list that scrolls smoothly on mid-range hardware:
- Under 100 rows, render everything. Windowing is premature.
- Between 100 and 1,000 rows, render everything, and keep each row under about 10 DOM nodes.
- Over 1,000 rows, or over 10 nodes per row, window it.
Measuring instead of guessing
Record a performance trace while scrolling and read two numbers: the longest task during the scroll, and how long recalculate style took. If the longest task stays under 16ms, the list is fine however many rows it holds.
What windowing costs
- Find-in-page only sees the rendered rows.
- Each row has to announce its position through
aria-setsizeandaria-posinset. - An anchor link into the list needs a scroll call rather than a fragment.
- Variable-height content needs measurement and invalidation.
Alternatives worth trying first
Pagination, a "load more" button, and collapsing groups each cut the node count without those costs, and they tend to match what a reader wants from a long list.
Related entries
- Virtual list. The implementation to reach for once the budget is exceeded.
- useIntersectionObserver hook. Drives the "load more" alternative.
Related entries
Virtual list
Render only the visible slice of a long list, using fixed-height windowing and an absolute spacer.
Memoization rules
A decision procedure for memo, useMemo and useCallback that avoids caching for its own sake.
useIntersectionObserver hook
Track element visibility for lazy loading, infinite scroll and scroll-spy navigation.