Skip to content
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(dashboard): reduce rerenders of DragDroppable #16525

Merged
merged 2 commits into from
Sep 7, 2021

Conversation

kgabryje
Copy link
Member

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 DragDroppable with whyDidYouRender library (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

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

CC @junlincc

@codecov
Copy link

codecov bot commented Aug 31, 2021

Codecov Report

Merging #16525 (f328b0d) into master (1f1e2dd) will increase coverage by 0.00%.
The diff coverage is 75.40%.

❗ Current head f328b0d differs from pull request most recent head 57e81e3. Consider uploading reports for the commit 57e81e3 to get more accurate results
Impacted file tree graph

@@           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           
Flag Coverage Δ
javascript 71.01% <67.64%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...end/src/dashboard/components/dnd/DragDroppable.jsx 94.59% <ø> (ø)
...ols/DndColumnSelectControl/utils/optionSelector.ts 46.15% <0.00%> (ø)
...d/src/dashboard/components/gridComponents/Tabs.jsx 86.60% <25.00%> (+0.12%) ⬆️
...rontend/src/dashboard/components/DashboardGrid.jsx 61.01% <33.33%> (+1.36%) ⬆️
superset/views/datasource/views.py 90.10% <50.00%> (-1.85%) ⬇️
...nd/src/dashboard/components/gridComponents/Tab.jsx 86.66% <66.66%> (+0.45%) ⬆️
...d/components/DashboardBuilder/DashboardBuilder.tsx 90.17% <94.11%> (+0.36%) ⬆️
superset/views/core.py 75.54% <95.23%> (+0.25%) ⬆️
superset/db_engine_specs/presto.py 89.95% <0.00%> (-0.42%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1f1e2dd...57e81e3. Read the comment docs.

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines 248 to 249
{/*
// @ts-ignore */}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was here before, but wondering why this is here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@kgabryje
Copy link
Member Author

kgabryje commented Sep 1, 2021

@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?

@villebro
Copy link
Member

villebro commented Sep 1, 2021

@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 JSON.stringify. I agree we should refrain fron stringifying whenever we can, and I also agree we should keep removal of stringification to future PRs. So no action needed here, just voicing my concerns/ignorance here 🙂

@kgabryje kgabryje merged commit 7faa5c6 into apache:master Sep 7, 2021
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
* perf(dashboard): reduce rerenders of DragDroppable

* lint fix
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
* perf(dashboard): reduce rerenders of DragDroppable

* lint fix
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.4.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 1.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants