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

fix(nativeFilters): Speed up native filters by removing unnecessary rerenders #25282

Merged

Conversation

Always-prog
Copy link
Contributor

SUMMARY

Currently, rendering 20+ filters takes not normal lot of time due to two issues:

  1. The issue with the Select filter. After rendering, Select Filter adds the __cache key to the dataMask, and changing dataMask triggering a redraw of all filters again. This happens for each Select filter in sequence. This can be resolved by adding __cache to the default dataMask.
  2. The issue with the dataMaskSelected in the hooks is that it is specified as an object, which always triggers a redraw. This can be resolved by setting dataMaskSelected to JSON.stringify.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before

2023-09-13_12-13-34.mp4

After

2023-09-13_12-14-27.mp4

TESTING INSTRUCTIONS

  1. Go to any dashboard
  2. Add 30 select filters
  3. Reload dashboard
  4. See that filters take a lot of time for before render.
    5 (optional). You can add console log to FilterBarScrollContext such as console.log('rerendered filters bar!') to see the number of times it logs.

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

@michael-s-molina michael-s-molina changed the title feat(nativeFilters): Speed up native filters by removing unnecessary rerenders fix(nativeFilters): Speed up native filters by removing unnecessary rerenders Sep 13, 2023
@michael-s-molina
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@michael-s-molina Ephemeral environment spinning up at http://54.202.180.9:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@kgabryje
Copy link
Member

I love to see such perf improvements!
1 question about dataMaskSelected - do you think it's possible to make the object keep the same reference when there are no changes, so that the dependency array doesn't trigger an update unnecessarily without using JSON.stringify?
If not, I see that dataMaskSelected is in many more dependency arrays - do you think we should update them all?

@Always-prog
Copy link
Contributor Author

@kgabryje Hi! I can't write code that keep reference if dataMask is no changed :P
And you're right, seems we don't need some JSON.stringify. I removed them.

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.

One small cosmetic nit. I agree with @kgabryje , IMO the need for doing JSON.stringify on deps arrays is a symptom of something being done wrong upstream. But if it gets very complex, I'm ok with this, too

@@ -123,6 +123,7 @@ const FilterBar: React.FC<FiltersBarProps> = ({
verticalConfig,
hidden = false,
}) => {
console.log('rerender');
Copy link
Member

Choose a reason for hiding this comment

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

Oops

Suggested change
console.log('rerender');
console.log('rerender');

@michael-s-molina
Copy link
Member

IMO the need for doing JSON.stringify on deps arrays is a symptom of something being done wrong upstream.

+1

@michael-s-molina
Copy link
Member

michael-s-molina commented Sep 13, 2023

I love the fix. It's a significant performance improvement but we need to make sure we're not breaking anything. Tagging @jinghua-qa and @sadpandajoe for awareness. I also tagged @justinpark as one of the reviewers.

@kgabryje
Copy link
Member

To be fair, we do use quite a lot of JSON.stringify around the native filters already. I think that if this one's hard to avoid, we should just proceed and attempt to clean the whole native filters code in a larger refactor effort when possible

@michael-s-molina
Copy link
Member

michael-s-molina commented Sep 13, 2023

To be fair, we do use quite a lot of JSON.stringify around the native filters already. I think that if this one's hard to avoid, we should just proceed and attempt to clean the whole native filters code in a larger refactor effort when possible

Fair point. Let's try to remove them but that shouldn't be a blocker.

@john-bodley john-bodley added the review:checkpoint Last PR reviewed during the daily review standup label Sep 13, 2023
@john-bodley john-bodley removed the review:checkpoint Last PR reviewed during the daily review standup label Sep 14, 2023
@Always-prog
Copy link
Contributor Author

Hi!
Cypress has failed due to billing plan exceeded.

https://github.com/apache/superset/actions/runs/6288585657/job/17074191658?pr=25282
image

@kgabryje
Copy link
Member

@Always-prog it’s been fixed already, I restarted the CI

@michael-s-molina
Copy link
Member

Hi! Cypress has failed due to billing plan exceeded.

The Cypress error was fixed by #25399. You may need to rebase your PR if that fix is not included in your commit history.

@Always-prog
Copy link
Contributor Author

@kgabryje Thank you!
@michael-s-molina CI tests has passed!

@justinpark
Copy link
Member

@Always-prog
Please add the following fix on useFilterDependencies which misses shallowEqual on useSelector

const dependencyIds = useSelector<any, string[] | undefined>(
state => state.nativeFilters.filters[id]?.cascadeParentIds,
);

import { shallowEqual, useSelector } from 'react-redux';
...
  const dependencyIds = useSelector<any, string[] | undefined>(
    state => state.nativeFilters.filters[id]?.cascadeParentIds,
    shallowEqual,
  );

@Always-prog
Copy link
Contributor Author

Always-prog commented Sep 27, 2023

@justinpark Added!

Copy link
Member

@justinpark justinpark left a comment

Choose a reason for hiding this comment

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

LGTM

@kgabryje kgabryje merged commit a0eeb4d into apache:master Sep 28, 2023
26 checks passed
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

@michael-s-molina michael-s-molina added the v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch label Sep 28, 2023
michael-s-molina pushed a commit that referenced this pull request Sep 28, 2023
…erenders (#25282)

Co-authored-by: JUST.in DO IT <[email protected]>
(cherry picked from commit a0eeb4d)
saghatelian added a commit to 10webio/superset that referenced this pull request Oct 23, 2023
* fix: is_select with UNION (apache#25290)

(cherry picked from commit bb002d6)

* fix: Add explicit ON DELETE CASCADE for dashboard_roles (apache#25320)

(cherry picked from commit d54e827)

* fix(chart): Supporting custom SQL as temporal x-axis column with filter (apache#25126)

Co-authored-by: Kamil Gabryjelski <[email protected]>

* fix: Use RLS clause instead of ID for cache key (apache#25229)

(cherry picked from commit fba66c6)

* fix: Improve the reliability of alerts & reports (apache#25239)

(cherry picked from commit f672d5d)

* fix: DashboardRoles cascade operation (apache#25349)

(cherry picked from commit a971a28)

* fix: datetime with timezone excel export (apache#25318)

Co-authored-by: Michael S. Molina <[email protected]>
(cherry picked from commit 5ebcd2a)

* fix: Workaround for Cypress ECONNRESET error (apache#25399)

(cherry picked from commit d76ff39)

* fix(sqllab): invalid persisted tab state (apache#25308) (apache#25398)

* fix: Rename on_delete parameter to ondelete (apache#25424)

(cherry picked from commit 893b45f)

* fix: preventing save button from flickering in SQL Lab (apache#25106)

(cherry picked from commit 296ff17)

* fix: chart import (apache#25425)

(cherry picked from commit a4d8f36)

* fix: swagger UI CSP error (apache#25368)

(cherry picked from commit 1716b9f)

* fix: smarter date formatter (apache#25404)

(cherry picked from commit f0080f9)

* fix(sqllab): invalid start date (apache#25437)

* fix(nativeFilters): Speed up native filters by removing unnecessary rerenders (apache#25282)

Co-authored-by: JUST.in DO IT <[email protected]>
(cherry picked from commit a0eeb4d)

* fix(SqlLab): make icon placement even (apache#25372)

(cherry picked from commit 11b49a6)

* fix: Duplicate items when pasting into Select (apache#25447)

(cherry picked from commit 7cf96cd)

* fix: update the SQLAlchemy model definition at json column for Log table (apache#25445)

(cherry picked from commit e83a76a)

* fix(helm chart): set chart appVersion to 3.0.0 (apache#25373)

* fix(mysql): handle string typed decimal results (apache#24241)

(cherry picked from commit 7eab59a)

* fix: Styles not loading because of faulty CSP setting (apache#25468)

(cherry picked from commit 0cebffd)

* fix(sqllab): error with lazy_gettext for tab titles (apache#25469)

(cherry picked from commit ddde178)

* fix: Address Mypy issue which is causing CI to fail (apache#25494)

(cherry picked from commit 36ed617)

* chore: Adds 3.0.1 CHANGELOG

* fix: Unable to sync columns when database or dataset name contains `+` (apache#25390)

(cherry picked from commit dbe0838)

* fix(sqllab): Broken query containing 'children' (apache#25490)

(cherry picked from commit b92957e)

* chore: Expand error detail on screencapture (apache#25519)

(cherry picked from commit ba541e8)

* fix: tags permissions error message (apache#25516)

(cherry picked from commit 50b0816)

* fix: Apply normalization to all dttm columns (apache#25147)

(cherry picked from commit 58fcd29)

* fix: REST API CSRF exempt list (apache#25590)

(cherry picked from commit 549abb5)

* fix(RLS): Fix Info Tooltip + Button Alignment on RLS Modal (apache#25400)

(cherry picked from commit a6d0e6f)

* fix: thubmnails loading - Talisman default config (apache#25486)

(cherry picked from commit 52f631a)

* fix(Presto): catch DatabaseError when testing Presto views (apache#25559)

Co-authored-by: Rui Zhao <[email protected]>
(cherry picked from commit be3714e)

* fix(Charts): Set max row limit + removed the option to use an empty row limit value (apache#25579)

(cherry picked from commit f556ef5)

* fix(window): unavailable localStorage and sessionStorage (apache#25599)

* fix: finestTemporalGrainFormatter (apache#25618)

(cherry picked from commit 62bffaf)

* fix: revert fix(sqllab): Force trino client async execution (apache#24859) (apache#25541)

(cherry picked from commit e56e0de)

* chore: Updates 3.0.1 CHANGELOG

* fix(sqllab): Mistitled for new tab after rename (apache#25523)

(cherry picked from commit a520124)

* fix(sqllab): template validation error within comments (apache#25626)

(cherry picked from commit b370c66)

* fix: avoid 500 errors with SQLLAB_BACKEND_PERSISTENCE (apache#25553)

(cherry picked from commit 99f79f5)

* fix(import): Make sure query context is overwritten for overwriting imports (apache#25493)

(cherry picked from commit a0a0d80)

* fix: permalink save/overwrites in explore (apache#25112)

Co-authored-by: Elizabeth Thompson <[email protected]>
(cherry picked from commit e58a3ab)

* fix(header navlinks): link navlinks to path prefix (apache#25495)

(cherry picked from commit 51c56dd)

* fix: improve upload ZIP file validation (apache#25658)

* fix: warning of nth-child (apache#23638)

(cherry picked from commit 16cc089)

* fix(dremio): Fixes issue with Dremio SQL generation for Charts with Series Limit (apache#25657)

(cherry picked from commit be82657)

---------

Co-authored-by: Beto Dealmeida <[email protected]>
Co-authored-by: John Bodley <[email protected]>
Co-authored-by: Zef Lin <[email protected]>
Co-authored-by: Kamil Gabryjelski <[email protected]>
Co-authored-by: Jack Fragassi <[email protected]>
Co-authored-by: Michael S. Molina <[email protected]>
Co-authored-by: JUST.in DO IT <[email protected]>
Co-authored-by: Jack <[email protected]>
Co-authored-by: Daniel Vaz Gaspar <[email protected]>
Co-authored-by: Stepan <[email protected]>
Co-authored-by: Corbin Bullard <[email protected]>
Co-authored-by: Gyuil Han <[email protected]>
Co-authored-by: Celalettin Calis <[email protected]>
Co-authored-by: Ville Brofeldt <[email protected]>
Co-authored-by: ʈᵃᵢ <[email protected]>
Co-authored-by: Michael S. Molina <[email protected]>
Co-authored-by: mapledan <[email protected]>
Co-authored-by: Igor Khrol <[email protected]>
Co-authored-by: Rui Zhao <[email protected]>
Co-authored-by: Fabien <[email protected]>
Co-authored-by: Hugh A. Miles II <[email protected]>
Co-authored-by: OskarNS <[email protected]>
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
@mistercrunch mistercrunch added 🍒 3.0.1 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.1.0 labels Mar 8, 2024
vinothkumar66 pushed a commit to vinothkumar66/superset that referenced this pull request Nov 11, 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/S v3.0 Label added by the release manager to track PRs to be included in the 3.0 branch 🍒 3.0.1 🍒 3.0.2 🍒 3.0.3 🍒 3.0.4 🚢 3.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants