UI5 Web Components · Table · Cahit Gürgüc
How the new table virtualizer keeps huge tables smooth – even when every row has a different height.
Press → / PgDn or scroll
Today
Why big tables are slow, and why rows of different heights make it hard.
Guessing, a clever tree, keeping your place, and not fighting your finger.
What an app has to do – with React, Angular or plain JavaScript.
What we measured, what we rejected, and how you can try it.
The problem
A table row is not one thing. It is a row element, cells, texts, tags, buttons – and each of them has its own small inner structure.
The browser has to create, style, lay out and paint every single one of them.
One row of our demo table: ≈58 elements.
100,000 rows: ≈5.8 million elements.
Try it on your phone: the buttons build simple rows (much lighter than real table rows) and measure the time on your device.
The classic trick
A screen shows maybe 10–20 rows. So we only create those – plus a few extra above and below.
While you scroll, rows that leave the screen are removed or reused for the rows that come in.
This is called virtualization: the table pretends to have 100,000 rows.
How it used to work
Which row is at the top of the screen? Divide the scroll position by the row height.
Our previous virtualizer worked exactly like this. It needed one fixed rowHeight for all rows.
Always right – because every row has exactly the same height.
The real world
Now the simple formula points to the wrong row. And heights keep changing while you look at them, so the content jumps.
We have to know where every row starts – without ever having seen most of them.
The time limit
A 120 Hz display shows a new picture 120 times per second. For each picture, the browser has 8.33 ms for everything: our code, styles, layout, painting.
If one frame takes too long, the display shows the old picture again. You see that as stutter.
So all of the following ideas have to be fast – not just correct.
Illustration. Measured: the virtualizer’s own work is about 0.1 ms per frame – even with a CPU slowed down 4×.
Idea 1
Rows we have never rendered get an estimated height: the average of all rows we have measured so far. Before the first measurement, the app can give a hint (estimatedRowHeight).
Every rendered row is measured and replaces its guess with the truth.
We only update the guess when we have measured twice as many rows as last time – so the scrollbar does not twitch with every new row.
Idea 2 · the cool part
To place a row we need the sum of all heights above it. Adding them one by one means up to 100,000 additions – in every frame.
Instead, we keep a small tree of partial sums (a Fenwick tree). Each box knows the total height of a block of rows. Any sum needs only a few boxes:
17 because 217 = 131,072 ≥ 100,000. With 1 million rows: 20 steps.
Idea 2, continued
Most rows are never measured. We don’t store a guess for each of them. Instead we keep two trees:
When the guess changes, nothing has to be updated – it is just one number in the formula.
| Adding one by one | Our trees | |
|---|---|---|
| Where does row i start? | up to 100,000 steps | ≤ 17 steps |
| Which row is at y? | up to 100,000 steps | ≤ 17 steps |
| One row changed its height | shift all rows below | ≤ 17 steps |
| The guess changed | update every guessed row | 1 step |
Idea 3
Asking “how tall is this row?” right after changing something forces the browser to calculate the layout immediately – again and again.
Instead we use a ResizeObserver: the browser does its layout once and then reports the sizes of all rows together.
Bonus: it also tells us when a row grows later – an image arrives, text rewraps, the phone rotates.
Idea 4
A row above you grows – maybe its data just arrived. Without care, everything below is pushed down and you lose your place.
We pick one row as the anchor and keep it exactly where it is. Which one?
👁 = the row you are reading. A row above it grows by 80 px.
Idea 5
The obvious way to keep your place is to correct the scroll position. But on phones and trackpads, changing the scroll position can stop momentum scrolling.
So we don’t touch it. We collect all corrections in one number – the drift – and move only the rows.
When scrolling stops, we hand the drift back to the scroll position. Rows and scroll position move together, so you see nothing.
The graphs show the scroll speed. A row above the screen grows by 120 px during momentum scrolling.
Idea 6
In our table, all rows share one grid, so a long text in one row widens the column for every row. That’s why the columns line up.
Positioning each row on its own pulls it out of the shared grid – every row sizes its columns differently.
So the visible rows stay in the grid, and we move them together as one block with a single translateY.
Moving a block this way skips layout and painting. CSS tricks that skip off-screen content would also isolate each row from the grid – and we have no off-screen rows anyway.
Idea 7
1,000,000 rows × 150 px = 150 million pixels. Browsers have a maximum element height – in Firefox about 18 million px.
So the scroll area never gets taller than 16 million px (tested in Chrome, Firefox and Safari):
Left: 150,000,000 px of rows. Right: the 16,000,000 px the browser actually scrolls (same scale).
Works with any framework
position
The table never creates rows itself – frameworks want to own their elements. How your app reuses its row elements is up to you:
keyColors = element identity. Scrolling by 2 rows: keyed creates 2 and deletes 2, positional rewrites all, pool reuses 2.
For app developers
to the range-change event of ui5-table-virtualizer.
rows first to last−1, in order, each with its position.
rows whose data is still loading with loading – keep the cells, empty is fine. The table draws the placeholder.
function Orders({ orders }) { const [range, setRange] = useState({ first: 0, last: 0 }); const rows = []; for (let i = range.first; i < range.last; i++) { const order = orders.get(i); // undefined while loading rows.push( <TableRow key={i} position={i} loading={!order}> <TableCell>{order?.id}</TableCell> <TableCell>{order?.text}</TableCell> </TableRow> ); } return ( <Table> <TableVirtualizer slot="features" rowCount={orders.size} onRangeChange={e => setRange(e.detail)} /> <TableHeaderRow slot="headerRow">…</TableHeaderRow> {rows} </Table> ); }
// 1. listen virtualizer.addEventListener("range-change", e => { const { first, last } = e.detail; // 2. render rows first..last-1 in order for (let i = first; i < last; i++) { const row = getRowElement(i); // reuse from a pool row.position = i; const order = store.get(i); // 3. flag rows without data row.loading = !order; if (order) fillCells(row, order); } releaseRowsOutside(first, last); // back to the pool });
Built in
Data often comes from a server. Until it arrives, a row only needs loading. The table takes care of the rest:
The server answers after 1.2 s. The marked row keeps its position.
Accessibility
Hold Page Down: the next target row usually does not exist yet. Most virtual lists lose the focus right here.
We remember the focus as a row number. Each key press is calculated from the guessed heights, so even a page of very different heights is one screen. The focus waits in the table until the row is there.
No key press is lost – even when the app renders late.
The app needs 400 ms to render new rows.
Just as important
Custom scroll physics never feels native. It breaks accessibility, find-in-page and scrolling inside the page.
Rows leave the shared grid, so columns stop lining up.
Can stop momentum scrolling on phones and trackpads. The drift solves it.
React and Angular want to own their elements. Two owners fight.
Forces a full layout for every row. The browser reports sizes for free.
Isolates rows from the grid. And there is nothing off-screen to skip.
100,000 additions per frame. The tree needs 17.
Positions jump when you scroll back. 1.7 MB for 100,000 rows is cheap.
Measured, not promised
| Scenario (5 s auto-scroll) | FPS | Frame time p95 | White space | Content jumps |
|---|---|---|---|---|
| 10,000 rows, 4,000 px/s | 120 | 9.3 ms | 0 | 0 |
| 10,000 rows, 12,000 px/s | 120 | 9.0 ms | 0 | 0 |
| Scrolling up into never-seen rows | 120 | 9.3 ms | 0 | 0 |
| 100,000 rows (15 M px of content) | 120 | 9.2 ms | 0 | 1 × 1.3 px |
| Data arrives after 400 ms (placeholders) | 120 | 9.3 ms | 0 | 0 |
Chrome 150, macOS, 12 cores, 120 Hz display. Automated scrolling. “Content jumps” = the row you read moved by more than 1 px.
Thank you!
Scan the code and try the demo on your phone: fling, rotate, switch the data size to 1,000,000 rows. We’d love your feedback – especially what feels wrong.