Skip to content

Commit e1df2f1

Browse files
committed
perf(layout): compute row heights in one pass and skip id lookups when no detail panel is open
1 parent 90dce3e commit e1df2f1

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎lib/hooks/core/useLayout.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,19 @@ export function useLayout<R extends GridRowModel>(params: UseLayoutParams<R>): L
255255
return rowHeight + getDetailPanelLayoutHeight(panelHeight, detailPanelHeights?.get(id));
256256
};
257257

258-
const rowHeights = unpinnedRows.map((row, index) => heightOf(row, pinnedTopRowsLength + index));
259-
260-
const cumulativeHeights = rowHeights.reduce((acc, height, index) => {
261-
acc.push((acc[index - 1] || 0) + height);
262-
return acc;
263-
}, [] as number[]);
258+
// One pass with preallocated arrays: this runs for every row after each sort or filter. With
259+
// no detail panel open every row has the plain height, so row ids are not looked up.
260+
const rowCount = unpinnedRows.length;
261+
const rowHeights = new Array<number>(rowCount);
262+
const cumulativeHeights = new Array<number>(rowCount);
263+
const anyPanelOpen = expandedRowIds.size > 0;
264+
let runningHeight = 0;
265+
for (let index = 0; index < rowCount; index++) {
266+
const height = anyPanelOpen ? heightOf(unpinnedRows[index], pinnedTopRowsLength + index) : rowHeight;
267+
rowHeights[index] = height;
268+
runningHeight = (runningHeight || 0) + height; // as before: a NaN total restarts from 0
269+
cumulativeHeights[index] = runningHeight;
270+
}
264271

265272
const skeletonCount = (paginationMode === 'infinite' && isLoading && unpinnedRows.length > 0)
266273
? Math.min(pageSize, 20)

0 commit comments

Comments
 (0)