-
Notifications
You must be signed in to change notification settings - Fork 843
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
Performance tweaking for DataGrid #2638
Conversation
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.
This is a great improvement and should certainly help make Discover feel a little snappier!
🎉
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.
Changes LGreatTM, pulled & tested locally. Love it, and thank you @mbondyra !
Missing a CHANGELOG.md entry - should get a quick note on the performance improvement in the top Bug Fixes section https://github.com/elastic/eui/blob/master/CHANGELOG.md |
# Conflicts: # CHANGELOG.md
Summary
I played a bit with the performance on
EuiDataGrid
component and I noticed that there's a visual lag for bigger datasets(around 100 rows and more). At the moment even the smallest change like selecting a different cell unnecessarily rerenders the whole table. Here's the gif with the updates highlighted and a React profiler view:The good news is there are a couple of easy gains to make it significantly faster (from 200ms to 10ms in dev environment for table of 100rows). The changes include:
React.memo
focusedCell
was passed to every Row component. But if we change the cell from [0,0] to [1,1], the row 3 doesn't have to know about the change because for it nothing changes (the cells inside the row 3 don't have to know it either). So instead of passing the [x,y] position offocusedCell
I propose to passfocusedCellPositionInTheRow
which is only thex
value of focused position.Example:
Let's say the cell [3,1] is focused.
The row 0 will get
focusedCellPositionInTheRow=null
row 1:
focusedCellPositionInTheRow=3
row 2:
focusedCellPositionInTheRow=null
row 3:
focusedCellPositionInTheRow=null
This way only the involved rows will be rerendered. I know we pay the cost of lower readability but... well... that's performance problems in its core, readability vs performance 😅
Here's the stats after the changes:

Checklist
[ ] Checked in dark mode[ ] Checked in mobile[ ] Checked in IE11 and Firefox[ ] Props have proper autodocs[ ] Added documentation examples[ ] Added or updated jest tests[ ] Checked for breaking changes and labeled appropriately[ ] Checked for accessibility including keyboard-only and screenreader modes