Appearance
Performance
The grid renders only the visible rows and columns (plus a small buffer), so the number of DOM elements does not depend on the size of the data.
vue
<template>
<div class="demo">
<div class="demo-toolbar">{{ ROWS.toLocaleString() }} rows × {{ COLUMNS }} columns, created in {{ duration }} ms</div>
<Datagrid :columns="columns" :rows="rows" :options="options" />
</div>
</template>
<script setup lang="ts">
import { shallowRef } from "vue";
import { Datagrid, type ColumnConfig, type GridOptions } from "@kitegrid/vue";
const COLUMNS = 50;
const ROWS = 100_000;
const start = performance.now();
const columns: Array<ColumnConfig> = Array.from({ length: COLUMNS }, (_, i) => ({
field: `c${i}`,
text: `Column ${i}`,
type: i % 3 === 0 ? "number" : undefined,
pinned: i === 0 ? "left" : undefined,
}));
// shallowRef: vue does not need to make every row reactive
const rows = shallowRef(
Array.from({ length: ROWS }, (_, row) => {
const data: Record<string, unknown> = {};
for (let i = 0; i < COLUMNS; i++) {
data[`c${i}`] = i % 3 === 0 ? (row * 7 + i * 13) % 1000 : `R${row} C${i}`;
}
return data;
})
);
const duration = Math.round(performance.now() - start);
const options: GridOptions = {
// fixed row heights are faster than measured row heights
rowHeight: 32,
selection: "Cell",
singleSelect: false,
defaultColumn: { sortable: true, filterable: true, resizeable: true, width: 120 },
};
</script>tsx
import { useState } from "react";
import { Datagrid, type ColumnConfig, type GridOptions } from "@kitegrid/react";
const COLUMNS = 50;
const ROWS = 100_000;
const columns: Array<ColumnConfig> = Array.from({ length: COLUMNS }, (_, i) => ({
field: `c${i}`,
text: `Column ${i}`,
type: i % 3 === 0 ? "number" : undefined,
pinned: i === 0 ? "left" : undefined,
}));
const options: GridOptions = {
// fixed row heights are faster than measured row heights
rowHeight: 32,
selection: "Cell",
singleSelect: false,
defaultColumn: { sortable: true, filterable: true, resizeable: true, width: 120 },
};
function createRows() {
const start = performance.now();
const rows = Array.from({ length: ROWS }, (_, row) => {
const data: Record<string, unknown> = {};
for (let i = 0; i < COLUMNS; i++) {
data[`c${i}`] = i % 3 === 0 ? (row * 7 + i * 13) % 1000 : `R${row} C${i}`;
}
return data;
});
return { rows, duration: Math.round(performance.now() - start) };
}
export default function BigData() {
// created once per mount, the array must keep its identity between renders
const [{ rows, duration }] = useState(createRows);
return (
<div className="demo">
<div className="demo-toolbar">
{ROWS.toLocaleString()} rows × {COLUMNS} columns, created in {duration} ms
</div>
<Datagrid columns={columns} rows={rows} options={options} />
</div>
);
}Benchmarks
Timings of the data pipeline for 100 000 rows (headless core, Node.js on a desktop CPU, fastest of 5 runs; each action is applied and reset):
| Action | Time |
|---|---|
| initialize | ~55 ms |
| sort by a number / date / text column | ~100 / ~150 / ~250 ms |
| column filter (text, number, date, set) | ~25–30 ms |
| quick filter, first search / each further keystroke | ~25 / ~15 ms |
| group by two columns with a sum | ~90 ms |
| select all rows and read the selected data | ~80 ms |
| CSV export | ~150 ms |
In the browser, scrolling 100 000 rows × 50 columns runs at 60 frames per second, also with the React component. Run the benchmark yourself with pnpm --filter @kitegrid/core benchmark (ROWS=1000000 for other sizes).
How the core keeps these times low:
- Sorting reads every value once and converts it into a numeric key (numbers, timestamps, or the rank of a text among the distinct texts), so the 1.7 million comparisons of 100 000 rows only compare numbers. Plain alphanumeric texts are ranked without the slow
Intl.Collator. - Plain fields are read directly, only the results of
valueGetterandvalueFormatterare cached. - The quick filter caches a search text per row, so typing only searches strings.
- Rows scrolled into view are rendered in the same frame, also in React (scroll updates are flushed synchronously).
- Row components are reused while scrolling. A row which disappears gives its component and DOM element to a row which appears, only the texts and classes are updated. Custom cell content (slots, render props, components) and detail rows are keyed by the row, so their internal state never moves to another row.
DOM order of the rows
Because row elements are reused, the order of the row elements in the DOM is not the displayed order (the rows are positioned absolutely). Screen readers use aria-rowindex. In end-to-end tests, select rows by aria-rowindex instead of their position in the DOM. With animationEnabled every row keeps its own element.
Bundle size
The packages contain readable builds for development (dist/index.js) and minified builds for production (dist/index.min.js). Bundlers which support the export condition production (Vite, webpack, Rollup) use the minified build automatically in production builds. In the minified core, the private members are renamed as well.
| Package | minified | gzip | brotli |
|---|---|---|---|
@kitegrid/core | 120 kB | 35.8 kB | 31.2 kB |
@kitegrid/vue | 57 kB | 16.6 kB | 15.0 kB |
@kitegrid/react | 41 kB | 12.8 kB | 11.6 kB |
styles (style.css) | 37 kB | 5.6 kB | 5.0 kB |
@kitegrid/export (without exceljs / pdfmake) | 5 kB | 2.2 kB | 1.9 kB |
A Vue application needs about 58 kB (gzip) for the grid, a React application about 54 kB.
Tips
- Use
shallowReffor rows. Deep reactivity of large arrays is expensive and not needed by the grid.
- Keep
columnsandoptionsstable (module constants oruseMemo), and memoize render props likecellRenderers.
- Set a
rowId. Row objects are reused on data updates, which keeps the selection and is faster. - Use a fixed
rowHeightfor large data sets. Rows do not need to be measured then. WithoutrowHeight, rows are measured with aResizeObserver, which allows content based row heights. - Avoid expensive
valueGetterandvalueFormatterfunctions. Their results are cached per cell, but they are called again after data changes. - Prefer formatters over slots and components for plain text. Slots and components are more expensive to render.
- Use pagination or server side data for data sets which are too large to be loaded into the browser.
- Update the data with a new array instead of mutating many rows and calling
refresh()for each change. - Mind the maximum height of the browsers. All rows together must not be higher than the maximum height of an element: about 17.9 million pixels in Firefox (roughly 550.000 rows with a height of 32px) and 33.5 million pixels in Chrome and Safari (roughly 1.000.000 rows). Use pagination for more rows.
Virtualization options
ts
virtualization: {
bufferRow: 1, // additional rows rendered above and below the viewport
bufferColumn: 1, // additional columns rendered left and right
}Columns with autoHeight are always rendered (because they define the height of the row), so keep their number small.