perf(dashboard): reduce rerenders of DragDroppable#16525
perf(dashboard): reduce rerenders of DragDroppable#16525kgabryje merged 2 commits intoapache:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #16525 +/- ##
=======================================
Coverage 76.71% 76.71%
=======================================
Files 1002 1002
Lines 53780 53807 +27
Branches 6859 6858 -1
=======================================
+ Hits 41257 41280 +23
- Misses 12286 12290 +4
Partials 237 237
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
villebro
left a comment
There was a problem hiding this comment.
Wow, incredible improvement again! I've said this before and I'll say this again - Given that we still don't have tightly enforced conventions in place for making sure that we can check for dashboardLayout in deps vs JSON.stringify(dashboardLayout), I expect us to hit some regression at some point by just checking if the object reference has changed. But in the long term I do feel we should aim to get rid of JSON.stringify in deps, so if we're confident this behavior works correctly in this case let's keep it this way for the sake of code cleanliness and perf (not sure how expensive JSON.stringify is, but I'm sure it adds up in a complex app like this).
| {/* | ||
| // @ts-ignore */} |
There was a problem hiding this comment.
This was here before, but wondering why this is here?
There was a problem hiding this comment.
There are some typing errors returned by DashboardComponent. We should definitely fix them... in a separate PR 🙂
I fixed those weird white spaces around ts-ignore though
|
@villebro I don't see any JSON.stringify in the files modified by this PR. Do you mean any specific place, or using JSON.stringify in deps array in general? I agree that we should limit using that as much as possible - maybe we can do that gradually as a side effect of other future PRs? |
I merely meant that it was difficult for me to assess where it was sufficient to pass the object as-is in the deps array vs running it through |
* perf(dashboard): reduce rerenders of DragDroppable * lint fix
* perf(dashboard): reduce rerenders of DragDroppable * lint fix
SUMMARY
Due to incorrect passing props to
DragDroppable(i.e. passing inline functions and objects instead of memoizing them first), the component was being rerendered multiple times (1609 in the case of initial render of Sales Dashboard from sample data).This PR improves that behaviour.
There's still a lot of room for improvement - in some cases it was problematic to memoize some functions without converting DragDroppable's parent from class to functional component. For that reason, there are still quite a lot of rerenders, especially in edit mode.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
I measured the number of rerenders of
DragDroppablewithwhyDidYouRenderlibrary (https://github.com/welldone-software/why-did-you-render). It reports every rerender of a component that wasn't necessary and could've been avoided (e.g. by memoizing props or using PureComponent).Before:
https://user-images.githubusercontent.com/15073128/131513340-9b1d96fc-052b-4f80-a7ca-44d116074c71.mov
After:
https://user-images.githubusercontent.com/15073128/131513453-44973062-5a48-4ef9-ad43-a1ee9ad8a96a.mov
TESTING INSTRUCTIONS
There should be no changes in how the dashboard works.
ADDITIONAL INFORMATION
CC @junlincc