A hundred thousand rows. Twenty in the DOM.
TanStack Virtual with its state in Pyreon signals. Only the rows on screen exist, and a scroll adds the rows coming in and removes the ones going out: the rows that stay do no work, because there is no component to re-render.
bun add @pyreon/virtual - vs react-virtual, Chromium
- faster on all 4 operationsMount, scroll, jump, unmount. One run, author-run.
- built on
@tanstack/virtual-coreSame measuring and range logic as react-virtual.- sizing
- fixed, variable, measuredVertical, horizontal and masonry lanes.
- scroll target
- an element or the window
useVirtualizer/useWindowVirtualizer.
- 3.25× faster unmount of a 10,000-row virtual list than
@tanstack/react-virtual(20 vs 65 µs)BENCHMARKS.md §2 Virtual list, real Chromium · final pass, one run - 1.15× faster mount (777 vs 897 µs); jump to row 5,000 1.10×BENCHMARKS.md §2 Virtual list · one run
- 20 rows in the DOM at row 50,000 of 100,000 (10 visible + 5 overscan each side)
useVirtualizerwith a 400 px viewport, 40 px rows andoverscan: 5, mounted and scrolled to row 50,000
synthetic · author-run · M3 Max · record of 2026-11-05
Every result, including where we lose →Long lists that stay quick.
Scrolling touches the edges only
Rows render through a keyed
<For by={(r) => r.index}>. A scroll step creates the rows entering and removes the rows leaving; the rest keep their DOM and run nothing.Signals out, signals in
virtualItems(),totalSize()andisScrolling()are signals, and the options are a function that reads signals. Filter the list andcountre-sizes the virtualizer on its own.Any row shape
Fixed heights, known variable heights, or measured on render with
measureElement. Horizontal lists and masonry lanes too, from the same core TanStack uses.Jump anywhere
instance.scrollToIndex(50_000)for "go to row",scrollToOffsetfor a saved position.
Same core. No list re-render per scroll step.
Each scroll step re-renders the list component and reconciles every visible row.
function List({ rows }: { rows: string[] }) {
const parentRef = useRef<HTMLDivElement>(null)
const v = useVirtualizer({
count: rows.length,
getScrollElement: () => parentRef.current,
estimateSize: () => 40,
overscan: 5,
})
return (
<div ref={parentRef} style={{ height: 400, overflow: 'auto' }}>
<div style={{ height: v.getTotalSize(), position: 'relative' }}>
{v.getVirtualItems().map((item) => (
<div key={item.key} style={{ position: 'absolute', top: 0,
width: '100%', height: item.size,
transform: `translateY(${item.start}px)` }}>
{rows[item.index]}
</div>
))}
</div>
</div>
)
}The component runs once. A scroll step adds and removes rows at the edges.
import { For } from '@pyreon/core'
import { useVirtualizer } from '@pyreon/virtual'
const List = (props: { rows: () => string[] }) => {
let scrollEl: HTMLElement | null = null
const v = useVirtualizer(() => ({
count: props.rows().length,
getScrollElement: () => scrollEl,
estimateSize: () => 40,
overscan: 5,
}))
return (
<div ref={(el) => (scrollEl = el)} style="height: 400px; overflow: auto">
<div style={() => `height: ${v.totalSize()}px; position: relative`}>
<For each={() => v.virtualItems()} by={(item) => item.index}>
{(item) => (
<div style={() => `position: absolute; top: ${item.start}px; height: ${item.size}px; width: 100%`}>
{props.rows()[item.index]}
</div>
)}
</For>
</div>
</div>
)
}Coming from TanStack Virtual (React)?
Options become a function; getters become signals.
const v = useVirtualizer({
count: rows.length,
getScrollElement: () => parentRef.current,
estimateSize: () => 40,
})
v.getTotalSize()
v.getVirtualItems()
v.scrollToIndex(5000)Every @tanstack/virtual-core option works the same (overscan, horizontal, lanes, gap, paddingStart, measureElement…). The Virtualizer instance is on .instance; its state is mirrored into the virtualItems, totalSize and isScrolling signals.
const v = useVirtualizer(() => ({
count: rows().length,
getScrollElement: () => scrollEl ?? null,
estimateSize: () => 40,
}))
v.totalSize()
v.virtualItems()
v.instance.scrollToIndex(5000)Scroll 100,000 rows.
The counters show how many rows exist in the DOM right now: about twenty at any position, out of 100,000.
- Ada · order #100000$20
- Grace · order #100001$57
- Linus · order #100002$94
- Margaret · order #100003$131
- Edsger · order #100004$168
- Barbara · order #100005$205
- Ken · order #100006$242
- Dennis · order #100007$279
- Ada · order #100008$316
- Grace · order #100009$353
- Linus · order #100010$390
- Margaret · order #100011$427
- Edsger · order #100012$464
- Barbara · order #100013$501
- Ken · order #100014$538
- Dennis · order #100015$575
Scroll with the wheel or a finger, or focus the list and use the arrow keys, Page Down and End.
- total rows100,000
- rows in the DOM0
- rows added or removed by the last scroll step0
Counted from the DOM by a MutationObserver: rows that stay in view are kept as they are, so a scroll touches only the rows entering and leaving.
Faster on all four operations.
Same virtual-core on both sides, so the difference is rendering: React re-renders the list on every scroll step, Pyreon patches the rows entering and leaving. One run in the browser; the happy-dom rows below come from a separate harness (overnight run, one run) and include a loss at mount.
- unmount20 µs65 µswin3.25×
- mount 10,000-row list777 µs897 µswin1.15×
- jump to row 5,000315 µs345 µswin1.10×
- scroll 60 steps of 5 rows3.53 ms3.68 mswin1.04×
- happy-dom: scroll → DOMwin1.4×
- happy-dom: mount 10k listlossreact-virtual 1.1×
Virtualization, the TanStack way, with signals.
useVirtualizerFor a scrolling element; returnsvirtualItems,totalSize,isScrollingand the coreinstance.useWindowVirtualizerFor a list that scrolls with the page; safe to render on the server.- Reactive options Read a signal in
countand the virtualizer follows. Changed a size estimate? Oneinstance.measure()re-sizes the list. item(index)Per-indexstart,sizeandlaneaccessors for measured rows, at no cost until you use them.- Measured rows
measureElementcorrects an estimate once a row renders. - Horizontal and lanes
horizontal: truefor carousels,lanesfor masonry grids. scrollToIndex/scrollToOffsetGo to row 50,000, or back to where the user was.- Overscan Render a few rows past each edge so fast scrolls do not flash blank.
- Detached at mountnext release A scroll element inserted after mount (a
<Show>, a portal) gets its observers re-attached instead of rendering zero rows. - Core utilities re-exported
Virtualizer,elementScroll,windowScroll,measureElement,defaultRangeExtractorand the observers.
Things to build with it.
The count reads a computed, so typing in the search box re-sizes the list and keeps only the visible matches in the DOM.
import { computed, signal } from '@pyreon/reactivity'
import { useVirtualizer } from '@pyreon/virtual'
const query = signal('')
const visible = computed(() =>
contacts().filter((c) => c.name.toLowerCase().includes(query().toLowerCase())),
)
const v = useVirtualizer(() => ({
count: visible().length,
getScrollElement: () => scrollEl ?? null,
estimateSize: () => 56,
overscan: 8,
}))No inner scroll box: the window is the scroller, and rows of different heights are measured as they render.
import { For } from '@pyreon/core'
import { useWindowVirtualizer } from '@pyreon/virtual'
const v = useWindowVirtualizer(() => ({
count: posts().length,
estimateSize: () => 240,
}))
<div style={() => `height: ${v.totalSize()}px; position: relative`}>
<For each={() => v.virtualItems()} by={(it) => it.index}>
{(it) => (
<article
data-index={it.index}
ref={(el) => v.instance.measureElement(el)}
style={() => `position: absolute; top: ${v.item(it.index).start()}px; width: 100%`}
>
{posts()[it.index]?.body}
</article>
)}
</For>
</div>Two hooks and the TanStack core.
Every export has a reference page with its signature, an example and the mistakes people make with it.
- useVirtualizer
- useWindowVirtualizer
- virtualItems
- totalSize
- isScrolling
- item
- instance
- Virtualizer
- elementScroll
- windowScroll
- measureElement
- observeElementRect
- observeElementOffset
- observeWindowRect
- observeWindowOffset
- defaultKeyExtractor
- defaultRangeExtractor
- UseVirtualizerOptions
- UseVirtualizerResult
- UseWindowVirtualizerOptions
- UseWindowVirtualizerResult
- VirtualItem
- VirtualizerOptions
- Range
- Rect
- ScrollToOptions
- ItemRegistry
- VirtualItemMeasurement
Good to know before you start.
Give a close estimateSize
The scrollbar is sized from it before rows are measured. A close guess keeps the thumb from jumping.
Find-in-page sees rendered rows only
Rows outside the window are not in the DOM, so the browser's search cannot find them. Put a search box on long lists.
Key rows by index
Use <For by={(item) => item.index}> so a scroll moves only the edges. A .map() without a key rebuilds every visible row.
Native lists are already lazy
On iOS and Android (native targets are experimental), put a <For> as the only child of <Scroll> and it becomes a LazyVStack or LazyColumn, no virtualizer needed. @pyreon/virtual itself is web.
What people ask first.
How does it compare with react-virtual?
Same virtual-core, rendered differently. In real Chromium at 10,000 rows, one run: mount 1.15×, 60 scroll steps 1.04×, jump to row 5,000 1.10×, unmount 3.25× faster. Under happy-dom the record shows scroll-to-DOM 1.4× faster and mount 1.1× slower; happy-dom is a JavaScript DOM, the browser figure is the one that counts.
Do I need it for a table?
For a few hundred rows, no. Past a few thousand, pair it with @pyreon/table: virtualize the row model and render only the window.
Does it work with server rendering?
useWindowVirtualizer checks for a browser before touching window, and both hooks start measuring on mount, so the server renders the list shell and the client fills the window.
Variable heights?
Yes. Pass a per-index estimateSize, or measure rows with measureElement and a data-index attribute, as in TanStack.
Ninety-nine thousand nine hundred and eighty rows, doing nothing.
bun add @pyreon/virtual