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(sqllab): perf regression on #21532 refactor #21632

Merged

Conversation

justinpark
Copy link
Member

@justinpark justinpark commented Sep 28, 2022

SUMMARY

This commit fixes the rendering perf regression from #21532

Since SqlLab consists of heavy rendering components, accessing the entire current queryEditor object can occur re-rendering on unnecessary children components.

https://github.com/apache/superset/pull/21532/files#diff-dac1ba995e65dfae7c9aa7a0a794036ace1eb83814e2101d354752da2bb41dfdR166-R172

This commit removes the currentQueryEditor selector and moved into AceEditorWrapper where the actual values are consumed.
This commit also introduces useQueryEditor hook which supports a syntax validation that helps to optimize the queryEditor value access.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

type.validation.mov

TESTING INSTRUCTIONS

npm run test

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: @EugeneTorap @zhaoyongjie

@codecov
Copy link

codecov bot commented Sep 28, 2022

Codecov Report

Merging #21632 (9ef8499) into master (5ea9249) will decrease coverage by 0.00%.
The diff coverage is 90.00%.

@@            Coverage Diff             @@
##           master   #21632      +/-   ##
==========================================
- Coverage   65.55%   65.54%   -0.01%     
==========================================
  Files        1798     1799       +1     
  Lines       68793    68814      +21     
  Branches     7326     7332       +6     
==========================================
+ Hits        45095    45106      +11     
- Misses      21823    21828       +5     
- Partials     1875     1880       +5     
Flag Coverage Δ
javascript 53.15% <90.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
superset-frontend/src/SqlLab/reducers/sqlLab.js 35.22% <ø> (ø)
...d/src/SqlLab/components/AceEditorWrapper/index.tsx 58.22% <50.00%> (-0.75%) ⬇️
...frontend/src/SqlLab/components/SaveQuery/index.tsx 76.74% <80.00%> (ø)
...d/src/SqlLab/components/QueryLimitSelect/index.tsx 100.00% <100.00%> (ø)
...c/SqlLab/components/RunQueryActionButton/index.tsx 72.72% <100.00%> (-0.81%) ⬇️
...d/src/SqlLab/components/ShareSqlLabQuery/index.tsx 80.76% <100.00%> (-1.99%) ⬇️
...frontend/src/SqlLab/components/SqlEditor/index.jsx 53.84% <100.00%> (-0.51%) ⬇️
...d/src/SqlLab/components/SqlEditorLeftBar/index.tsx 52.23% <100.00%> (-2.05%) ⬇️
...-frontend/src/SqlLab/hooks/useQueryEditor/index.ts 100.00% <100.00%> (ø)
...ugins/plugin-chart-echarts/src/Gauge/buildQuery.ts 66.66% <0.00%> (-8.34%) ⬇️
... and 15 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@EugeneTorap
Copy link
Contributor

LGTM! Good fix to prevent re-rendering AceEditorWrapper.
I've prepared a #21650 PR for others SqlEditor child components to use queryEditorId.

@justinpark justinpark force-pushed the fix--perf-regression-on-sqllab-editor branch from afb6c4d to 0d6638e Compare September 29, 2022 20:36
@pull-request-size pull-request-size bot added size/L and removed size/M labels Sep 29, 2022
@justinpark justinpark force-pushed the fix--perf-regression-on-sqllab-editor branch from cb4100b to b8d18f2 Compare September 30, 2022 03:35
const middlewares = [thunk];
const mockStore = configureStore(middlewares);

describe('useQueryEditor', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you avoid nesting? You can just use test for each test case in the file.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

import { shallowEqual, useSelector } from 'react-redux';
import { SqlLabRootState, QueryEditor } from 'src/SqlLab/types';

export default function useQueryEditor<T extends keyof QueryEditor>(
Copy link
Member

Choose a reason for hiding this comment

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

I love this hook! Great improvement to code readability.

Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

LGTM, work as expected. One suggestion for this part is that should disable the Run button when the selection area is 1) empty or 2) beginning a comment(--) of SQL and only 1 line.

selection.in.SQLLab.mov

@justinpark
Copy link
Member Author

LGTM, work as expected. One suggestion for this part is that should disable the Run button when the selection area is 1) empty or 2) beginning a comment(--) of SQL and only 1 line.

selection.in.SQLLab.mov

@zhaoyongjie I made changes for this improvement

run.selection.mov

@zhaoyongjie
Copy link
Member

LGTM, work as expected. One suggestion for this part is that should disable the Run button when the selection area is 1) empty or 2) beginning a comment(--) of SQL and only 1 line.
selection.in.SQLLab.mov

@zhaoyongjie I made changes for this improvement
run.selection.mov

Thanks for tackling the long-term UX issue!

@zhaoyongjie zhaoyongjie merged commit 8d1b7ec into apache:master Oct 3, 2022
sadpandajoe added a commit to preset-io/superset that referenced this pull request Oct 17, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.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 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants