-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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] Scroll performance improvements #9037
Conversation
Netlify deploy previewNetlify deploy preview: https://deploy-preview-9037--material-ui-x.netlify.app/ Updated pagesThese are the results for the performance tests:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work 👏
Thank you!
Should I merge this one despite the argos differences or should I debug them? |
@romgrk We can ignore those flags diffs, our teammates say they saw them in other PRs as well. Could you merge the master into this branch? I'm surprised to see the grid on these screenshots: It should overflow after #9179 was merged, and I would expect Argos to have overflown screenshots as a reference for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! 🚀
getCellClassName, | ||
} = rootProps; | ||
const { slots, slotProps, disableColumnReorder } = rootProps; | ||
const CellComponent = slots.cell === GridCellV7 ? GridCellV7 : GridCellWrapper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do differently here and always render GridCellWrapper
. There's some code duplication between these two components that make the file very long to read and understand. For example, the logic to compute params to pass to renderEditCell
is the same. The difference is that GridCellV7
computes these params and renders the cell content, while GridCellWrapper
computes the params and calls React.createElement
with it. I don't know if it's worth it to improve this, duplicated code might be better than wrong abstractions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are more details in some collapsed thread above, but the performance improvements required to move some of the logic inside the cells, but doing so affected the cell's props which are public, so the wrapper is there to provide a compatibility layer until V7. At V7, we can remove the duplicated code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m4theushw relevant discussion: #9037 (comment)
Co-authored-by: Matheus Wichman <matheushw@outlook.com> Signed-off-by: Rom Grk <romgrk@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
(_, ev) => { | ||
if (ev.relatedTarget?.className.includes(gridClasses.columnHeader)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this in #9336
>(function GridVirtualScroller(props, ref) { | ||
const { className, ...other } = props; | ||
const rootProps = useGridRootProps(); | ||
const classes = useUtilityClasses(rootProps); | ||
|
||
return ( | ||
<VirtualScrollerRoot | ||
ref={ref} | ||
className={clsx(classes.root, className)} | ||
{...props} | ||
className={clsx(classes.root, props.className)} | ||
ownerState={rootProps} | ||
{...other} | ||
/> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there are a good number of cases in Material UI where we could apply this optimization. To consider if it's worth doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we're doing a lot of allocations. There is also this issue with the spread operator.
import * as React from 'react'; | ||
import { fastObjectShallowCompare } from './fastObjectShallowCompare'; | ||
|
||
export function fastMemo<T>(component: T): T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it could be great to leave a comment that explains how this comparison is different from the one of React https://github.com/facebook/react/blob/4ddc019aca8e08fd59cb43de5e0032be77d6174e/packages/react-reconciler/src/ReactFiberBeginWork.js#L570
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it goes faaaaast, but yeah we should explain also fastObjectShallowCompare
, it's tailored for a specific use-case.
"eslint": "eslint . --cache --report-unused-disable-directives --ext .js,.ts,.tsx --max-warnings 0", | ||
"eslint:fix": "yarn eslint --fix", | ||
"eslint:ci": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx --max-warnings 0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the main repo, these are called "lint" (there are json, esm, css, etc. types of lints), I find it confusing. It's better here with eslint.
Closes #569
Closes #9013
Discussion #9001
This PR improves the scrolling performance as well as the overall performance by reducing the amount of re-renders, by applying the solution in point 1 of the discussion linked above. I have not included the proposed
useGridRootPropsSelector
in this PR to limit the scope & facilitate reviews. It can be added independently later.Tasks:
Below are profiles of scrolling the following demo:
CPU: Intel Core 13th gen i7