-
Notifications
You must be signed in to change notification settings - Fork 380
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
perf(react-grid): avoid unnecessary row rerendering #1959
perf(react-grid): avoid unnecessary row rerendering #1959
Conversation
packages/dx-react-grid/src/components/table-layout/virtual-row-layout.test.tsx
Show resolved
Hide resolved
packages/dx-react-grid/src/components/table-layout/virtual-row-layout.test.tsx
Outdated
Show resolved
Hide resolved
packages/dx-react-grid/src/components/table-layout/virtual-row-layout.tsx
Outdated
Show resolved
Hide resolved
packages/dx-react-grid/src/components/table-layout/virtual-row-layout.tsx
Outdated
Show resolved
Hide resolved
|
||
const propsAreEqual = argumentsShallowEqual(nextColumns, prevColumns) | ||
&& argumentsShallowEqual(nextColSpans, prevColSpans) | ||
&& prevRow === nextRow; |
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.
Since it is all about performance the prevRow === nextRow
check should be moved to the beginning of the method.
Array lengths compare should be moved as well.
if (prevRow !== nextRow || prevCells.length !== nextCells.length) {
return true;
}
It would allow to avoid unnecessary arrays creation and comparing.
shouldComponentUpdate(nextProps) { | ||
const { cells: prevCells, row: prevRow } = this.props; | ||
const { cells: nextCells, row: nextRow } = nextProps; | ||
const [nextColumns, nextColSpans] = nextCells.reduce(reducer, [[], []]); |
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.
How about avoiding creation of two auxiliary arrays?
const areNotEqual = nextCells.some((nextCell, i) => {
const prevCell = prevCells[i];
return prevCell.column !== nextCell.column || prevCell.colSpan !== nextCell.colSpan;
});
Fixes #1925