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): decrease number of rerenders of FiltersBadge #16545

Merged
merged 3 commits into from
Sep 7, 2021

Conversation

kgabryje
Copy link
Member

@kgabryje kgabryje commented Sep 1, 2021

SUMMARY

Due to incorrect passing of props and setting state of FiltersBadge, we were rerendering the component multiple times. It's very expensive, as FiltersBadge calls selectIndicatorsForChart and selectNativeIndicatorsForChart functions, which traverse dashboard layout tree. Rerendering filters badge for every chart resulted in thousands of unnecessary traverses of dashboard layout tree, causing the performance to take a hit. This PR introduces caching and memoization for FiltersBadge, which reduces the amount of redundant rerenders.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

I measured the number of rerenders of FiltersBadge 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/131681210-7fd4ff10-fd9d-49c3-b467-2448eb99f7c8.mov

After:
https://user-images.githubusercontent.com/15073128/131681806-7f1da2f8-5ae5-416b-a3c3-6879ce4e4f7f.mov

TESTING INSTRUCTIONS

Everything should work as before

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 Sep 1, 2021

Codecov Report

Merging #16545 (1142246) into master (1f1e2dd) will increase coverage by 0.03%.
The diff coverage is 95.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16545      +/-   ##
==========================================
+ Coverage   76.71%   76.74%   +0.03%     
==========================================
  Files        1002     1002              
  Lines       53780    53846      +66     
  Branches     6859     6893      +34     
==========================================
+ Hits        41257    41325      +68     
+ Misses      12286    12285       -1     
+ Partials      237      236       -1     
Flag Coverage Δ
javascript 71.08% <95.91%> (+0.08%) ⬆️

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

Impacted Files Coverage Δ
...nd/src/dashboard/components/FiltersBadge/index.tsx 92.92% <94.23%> (+6.17%) ⬆️
...src/dashboard/components/FiltersBadge/selectors.ts 79.59% <97.67%> (+5.25%) ⬆️
...end/src/dashboard/components/SliceHeader/index.tsx 92.72% <100.00%> (+0.27%) ⬆️

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...1142246. Read the comment docs.

@stephenLYZ
Copy link
Member

Thanks for the improvement! The code looks good to me.

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.

Did my best to go through all code changes with a magnifying glass, and everything looks really clean. Also did my best to break this in testing, but wasn't able to find any problems; LGTM 👍

@kgabryje kgabryje merged commit effcf3b into apache:master Sep 7, 2021
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
…#16545)

* perf(dashboard): decrease rerenders in FiltersBadge

* implement caching of dashboard filter indicators

* Implement caching for native filter indicators
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
…#16545)

* perf(dashboard): decrease rerenders in FiltersBadge

* implement caching of dashboard filter indicators

* Implement caching for native filter indicators
@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.

4 participants