Skip to content

Speed up DataGrid scrolling on wide / large tables#287

Draft
debba wants to merge 2 commits into
mainfrom
perf/datagrid-scroll
Draft

Speed up DataGrid scrolling on wide / large tables#287
debba wants to merge 2 commits into
mainfrom
perf/datagrid-scroll

Conversation

@debba
Copy link
Copy Markdown
Collaborator

@debba debba commented Jun 4, 2026

Scrolling a table with ~500 rows and 30-40 columns was painfully slow. The grid only virtualized rows, so every scroll tick re-rendered the whole visible <tbody> (≈30 rows × 40 cells) from scratch, and each row was re-measured on the fly with a per-row ResizeObserver.

What changed

  • The per-row render now lives in a React.memo component (DataGridRow). All the stable, grid-wide dependencies are bundled into one memoized rowCtx object, and the volatile per-row bits (isSelected, editing/focused/expanded column, …) are passed as plain primitives. During a vertical scroll only the rows that actually changed re-render — the rest bail out of the shallow compare.
  • handleCellDoubleClick, handleEditCommit and handleKeyDown are now useCallbacks (they read the live editingCell through a ref), otherwise the memo would never hold across re-renders.
  • formatCellValue is computed once per cell instead of twice (it was being run again just for the title tooltip).
  • Rows now have a fixed height and no longer use measureElement — same approach MiniResultGrid already uses. No more layout thrashing while scrolling.
  • The small default-cell render helper moved to src/utils/dataGridCell.tsx with unit tests.

Behaviour is unchanged: inline editing, JSON/text expansion, FK/blob buttons, selection highlighting, sticky # column and sticky header all work as before.

Trying it out

There's now a perf_demo database in the demo stack with a wide_table of 50 columns × 50,000 rows on both MySQL and Postgres, with a mix of column types so the various cell renderers get exercised. Bring up the stack and open perf_demo.wide_table:

docker compose -f demo/docker-compose.yml up -d

The SQL is generated by demo/generate-perf-sql.py and the connections are already in demo/connections.json.

Notes

  • Column (horizontal) virtualization was intentionally left out for now — with row memoization in place scrolling is fluid, and that change is much riskier (sticky header, sticky # column, expansion colSpan). Easy follow-up if very wide tables still feel heavy.
  • tsc, eslint and the full test suite (2508 tests) are green.

Worth profiling with React DevTools on the 50k×50 table to confirm rows that stay on screen don't re-render mid-scroll.

debba added 2 commits June 4, 2026 16:15
…umns

Scrolling tables with ~500 rows and 30-40 columns was very laggy: the
whole tbody re-rendered on every scroll tick (no row/cell memoization)
and each row was dynamically re-measured.

- Extract the per-row render into a React.memo MemoRow (DataGridRow.tsx).
  Stable per-grid deps are bundled into one memoized rowCtx so the
  default shallow compare only re-renders rows that actually changed;
  volatile per-row values are passed as primitives.
- Stabilize handleCellDoubleClick/handleEditCommit/handleKeyDown with
  useCallback (reading live editingCell via a ref) so the memo holds.
- Compute formatCellValue once per cell (was twice: title + display).
- Fixed row height (height:35) and drop measureElement/data-index from
  the rows, matching the proven fixed-size pattern in MiniResultGrid.
- Move the cell default-render helper to src/utils/dataGridCell.tsx and
  add unit tests.
…res)

Heavy wide_table seed in a dedicated perf_demo database, added to the
existing demo stack, to reproduce and profile DataGrid scroll perf.
Mixed column types (int/bigint/decimal/double/varchar/text/date/
datetime/boolean/JSON). SQL generated by demo/generate-perf-sql.py;
pre-configured connections added to demo/connections.json.
@thomaswasle
Copy link
Copy Markdown
Contributor

Tested with my own much larger table and it feels good. A great improvement. Also the codechanges look good to me.

@debba
Copy link
Copy Markdown
Collaborator Author

debba commented Jun 4, 2026

@thomaswasle thanks a lot for your feedback 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants