Q45: How does Windowing/Virtualization improve long list rendering performance?
List Virtualization (using tools like react-window or tanstack-virtual) renders only the visible DOM items currently inside the user's scroll viewport, dynamically creating and destroying DOM elements as scrolling occurs. This keeps DOM node counts under ~50 regardless of list size.
React Window Virtualized List
import { FixedSizeList as List } from 'react-window';
function VirtualList({ items }) {
return (
<List height={400} itemCount={items.length} itemSize={35} width={300}>
{({ index, style }) => (
<div style={style}>Item {items[index]}</div>
)}
</List>
);
}react-window renders only ~12 DOM rows required to fill the 400px height window.
Key Takeaways
Renders only visible items in scroll viewports.
Drastically lowers DOM node counts and memory consumption for thousands of array records.
Knowledge Check
How many DOM elements are rendered on screen when displaying a virtualized list of 100,000 items with a viewport capacity of 15 rows?