Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Refactor: row virtualization & rendering #12247

Merged
merged 11 commits into from
Feb 28, 2024

Conversation

romgrk
Copy link
Contributor

@romgrk romgrk commented Feb 28, 2024

A few performance & refactor changes for the row rendering.

Based on #12238

Changes:

  • Remove offsets object to avoid re-renders
  • Avoid colspan calculation by default. No colspan data now implies { colSpan: 1 }
  • Simplify out-of-viewport focused cell rendering

Very limited performance gains, around 3%, but it's always nice to shave off some CPU time during scrolling.

@mui-bot
Copy link

mui-bot commented Feb 28, 2024

Deploy preview: https://deploy-preview-12247--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against e8a6ebb

@romgrk romgrk marked this pull request as ready for review February 28, 2024 18:26
) {
isRowWithFocusedCellNotInRange = true;
const firstRowToRender = renderContext.firstRowIndex;
const lastRowToRender = Math.min(renderContext.lastRowIndex, rowModels.length);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in some cases renderContext.lastRowIndex is greater than rowModels.length. It's not a new bug, it's just that before this PR the Math.min operation was hiding as rows.slice(firstRowToRender, lastRowToRender).

The root cause is that renderContext lags behind the rows when the "view" changes (e.g. filter modified, row expanded/collapsed, sorting modifier, etc). I've partially addressed the issue with the useGridApiEventHandler calls below, but some cases remain. I don't have enough time to hunt them all down in this PR.

@romgrk romgrk changed the title [DataGrid] Refactor: row rendering [DataGrid] Refactor: row virtualization & rendering Feb 28, 2024
Comment on lines 37 to +40
NONE,
LEFT,
RIGHT,
VIRTUAL,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've introduced the "virtual" term to refer to out-of-viewport focused cells that need to be rendered to keep their DOM state alive.

Copy link
Member

@cherniavskii cherniavskii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, love the simplifications!

@romgrk romgrk merged commit 0bb5ec1 into mui:next Feb 28, 2024
17 checks passed
@romgrk romgrk deleted the perf-offsets-refactor branch February 28, 2024 22:23
@zannager zannager added the component: data grid This is the name of the generic UI component, not the React module! label Feb 29, 2024
thomasmoon pushed a commit to thomasmoon/mui-x that referenced this pull request Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants