Performance tweaking for DataGrid#2638
Merged
mbondyra merged 4 commits intoelastic:masterfrom Dec 12, 2019
Merged
Conversation
mbondyra
commented
Dec 12, 2019
myasonik
approved these changes
Dec 12, 2019
Contributor
myasonik
left a comment
There was a problem hiding this comment.
This is a great improvement and should certainly help make Discover feel a little snappier!
🎉
chandlerprall
approved these changes
Dec 12, 2019
Contributor
chandlerprall
left a comment
There was a problem hiding this comment.
Changes LGreatTM, pulled & tested locally. Love it, and thank you @mbondyra !
Contributor
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I played a bit with the performance on
EuiDataGridcomponent 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.memofocusedCellwas 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 offocusedCellI propose to passfocusedCellPositionInTheRowwhich is only thexvalue of focused position.Example:
Let's say the cell [3,1] is focused.
The row 0 will get
focusedCellPositionInTheRow=nullrow 1:
focusedCellPositionInTheRow=3row 2:
focusedCellPositionInTheRow=nullrow 3:
focusedCellPositionInTheRow=nullThis 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