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(native-filters): Decrease number of unnecessary rerenders in native filters #17115

Merged
merged 3 commits into from
Oct 18, 2021

Conversation

kgabryje
Copy link
Member

@kgabryje kgabryje commented Oct 14, 2021

SUMMARY

The goal of this PR is to remove redundant rerenders of key components that build FilterBar in order to enhance the performance of native filters.
Components refactored: FilterBar, FilterControls, FilterControl, FilterValue, CascadePopover.
The method was similar to the one used in PRs #16421, #16444, #16525, #16545.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

The number of redundant rerenders of key components the changes (measured by counting logs produced by whyDidYouRender library) - tested on Video Game Sales dashboard with 5 native filters added:

BEFORE

  • FilterBar - 182
  • FilterControls - 252
  • CascadePopover - 960
  • FilterControl - 985
  • FilterValue - 760

After

  • FilterBar - 0
  • FilterControls - 0
  • CascadePopover - 0
  • FilterControl - 0
  • FilterValue - 20

Loading time on large test dashboard (~80 charts, 15 native filters) - measured as time from opening the dashboard to all charts and native filters fully loaded:

BEFORE
~60 seconds

before.mov

AFTER
~45 seconda

after.mov

TESTING INSTRUCTIONS

Every feature related to native filters should work the same 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 @rusackas

@kgabryje kgabryje marked this pull request as draft October 14, 2021 12:44
@kgabryje kgabryje marked this pull request as ready for review October 15, 2021 12:13
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.

AMAZING work! So much unnecessary rerendering cleaned up here, wow! Code LGTM and works very well! 👍

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Left some non-blocking comments. Unfortunately, we still don't have enough automated tests to make us feel safe merging these types of changes. Can we get @jinghua-qa approval before merging?

@@ -73,25 +72,37 @@ const FilterControls: FC<FilterControlsProps> = ({
const dashboardHasTabs = useDashboardHasTabs();
const showCollapsePanel = dashboardHasTabs && cascadeFilters.length > 0;

const cascadePopoverFactory = useCallback(
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't be useMemo here? Why are you preserving the instance of the function instead of its result?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a function, because the result depends on index which we get from portalNodes.map. Here the result will be memoized for each index value

@@ -274,6 +281,8 @@ const FilterBar: React.FC<FiltersBarProps> = ({
);
const isInitialized = useInitialization();

const tabPaneStyle = useMemo(() => ({ overflow: 'auto', height }), [height]);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this overkill? I remembered this point.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we didn't useMemo here we'd get a different object on each render, meaning the prop through which we pass that object would change and trigger rerender

@michael-s-molina
Copy link
Member

The difference in the number of renders is remarkable! Really cool work! 🚀

@suddjian
Copy link
Member

/testenv up FEATURE_DASHBOARD_NATIVE_FILTERS=true FEATURE_DASHBOARD_CROSS_FILTERS=true FEATURE_DASHBOARD_NATIVE_FILTERS_SET=true FEATURE_DASHBOARD_FILTERS_EXPERIMENTAL=true

@github-actions
Copy link
Contributor

@suddjian Ephemeral environment spinning up at http://52.25.11.193:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@graceguo-supercat
Copy link

Thanks so much for the work! let's merge it into master and I will test it with our benchmark dashboards to see the improvement.

@kgabryje kgabryje force-pushed the perf/native-filters branch from 00ca6c4 to cf328e6 Compare October 18, 2021 12:10
@codecov
Copy link

codecov bot commented Oct 18, 2021

Codecov Report

Merging #17115 (cf328e6) into master (37944e1) will increase coverage by 0.00%.
The diff coverage is 85.31%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #17115   +/-   ##
=======================================
  Coverage   76.89%   76.90%           
=======================================
  Files        1038     1038           
  Lines       55515    55540   +25     
  Branches     7564     7564           
=======================================
+ Hits        42690    42712   +22     
- Misses      12575    12578    +3     
  Partials      250      250           
Flag Coverage Δ
javascript 70.92% <85.31%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...src/dashboard/components/DashboardBuilder/state.ts 71.42% <50.00%> (-1.75%) ⬇️
...ts/nativeFilters/FilterBar/FilterControls/state.ts 82.35% <70.00%> (+3.78%) ⬆️
...board/components/nativeFilters/FilterBar/index.tsx 88.09% <75.00%> (-0.10%) ⬇️
...c/filters/components/Select/SelectFilterPlugin.tsx 80.64% <75.00%> (-0.47%) ⬇️
...src/filters/components/Range/RangeFilterPlugin.tsx 88.57% <87.17%> (+0.33%) ⬆️
...ilters/FilterBar/FilterControls/FilterControls.tsx 80.85% <87.50%> (+0.85%) ⬆️
...d/src/filters/components/Time/TimeFilterPlugin.tsx 84.37% <90.00%> (+1.04%) ⬆️
...veFilters/FilterBar/FilterControls/FilterValue.tsx 69.56% <94.44%> (+1.04%) ⬆️
...components/DashboardBuilder/DashboardContainer.tsx 85.71% <100.00%> (+1.71%) ⬆️
.../FilterBar/CascadeFilters/CascadePopover/index.tsx 63.23% <100.00%> (ø)
... and 3 more

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 37944e1...cf328e6. Read the comment docs.

@kgabryje kgabryje merged commit 2ad9101 into apache:master Oct 18, 2021
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

@kgabryje
Copy link
Member Author

@graceguo-supercat Please let me know the results once you've tested 🙂

opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
…ive filters (apache#17115)

* perf(native-filters): decrease number of redundant rerenders

* More perf improvements

* lint fix
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.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/XL 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants