-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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(sqllab): Rendering perf improvement using immutable state #20877
perf(sqllab): Rendering perf improvement using immutable state #20877
Conversation
Codecov Report
@@ Coverage Diff @@
## master #20877 +/- ##
==========================================
+ Coverage 66.27% 66.34% +0.07%
==========================================
Files 1770 1772 +2
Lines 67543 67570 +27
Branches 7185 7187 +2
==========================================
+ Hits 44764 44831 +67
+ Misses 20940 20893 -47
- Partials 1839 1846 +7
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@justinpark Ephemeral environment creation is currently limited to committers. |
/testenv up |
/testenv up |
@ktmud Ephemeral environment spinning up at http://34.220.154.64:8080. Credentials are |
4ca0186
to
e4d3876
Compare
/testenv up |
@ktmud Ephemeral environment spinning up at http://34.217.34.22:8080. Credentials are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the SQL Lab code is a mystery to me. But I've tested this quite extensively locally and did see significant improvements in typing performance in SQL editor. I trust the test cases to make sure the majority of the happy paths are still happy.
sql: 'SELECT *\nFROM\nWHERE', | ||
name: 'Untitled Query 1', | ||
schemaOptions: [{ value: 'main', label: 'main', name: 'main' }], | ||
schemaOptions: [{ value: 'main', label: 'main', title: 'main' }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we changing this to title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hughhhh This change(title -> name) accidentally happened here while the PR made the change for queryEditor title to name.
cc: @lyndsiWilliams
I reverted this change to pass the type role since I'm following this type definition
and it's also allocated as title
here:
superset/superset-frontend/src/components/DatabaseSelector/index.tsx
Lines 224 to 228 in eb5369f
const options = json.result.map((s: string) => ({ | |
value: s, | |
label: s, | |
title: s, | |
})); |
a4dcfe2
to
f282688
Compare
/testenv up |
@@ -178,7 +193,9 @@ export default function SaveQuery({ | |||
onHide={() => setShowSaveDatasetModal(false)} | |||
buttonTextOnSave={t('Save & Explore')} | |||
buttonTextOnOverwrite={t('Overwrite & Explore')} | |||
datasource={getDatasourceAsSaveableDataset(query)} | |||
datasource={ | |||
getDatasourceAsSaveableDataset(query) as any as ISaveableDatasource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are casting as any
and then ISaveableDatasource
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh it needed this custom type cast but no longer needed. I reverted this change.
@hughhhh Ephemeral environment spinning up at http://34.217.110.42:8080. Credentials are |
f282688
to
7417f72
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nits, but one could pose a runtime error.
superset-frontend/src/SqlLab/App.jsx
Outdated
@@ -91,6 +94,12 @@ const sqlLabPersistStateConfig = { | |||
const result = { | |||
...initialState, | |||
...persistedState, | |||
sqlLab: { | |||
...(persistedState && persistedState.sqlLab), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if persistedState
is null or undefined, this will error when you try to spread it. I'd recommend a default of an empty object.. maybe something like
...(persistedState && persistedState.sqlLab), | |
...(persistedState?.sqlLab || {}), |
@@ -620,6 +677,7 @@ export function switchQueryEditor(queryEditor, displayLimit) { | |||
return function (dispatch) { | |||
if ( | |||
isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE) && | |||
queryEditor && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use optional chaining here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
const qe = getUpToDateQuery(getState(), queryEditor, queryEditor.id); | ||
const query = { | ||
dbId: qe.dbId, | ||
sql: qe.selectedText ? qe.selectedText : qe.sql, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
sql: qe.selectedText ? qe.selectedText : qe.sql, | |
sql: qe.selectedText || qe.sql, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cypress change LGTM
|
||
return ( | ||
<TabTitleWrapper> | ||
<Dropdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this was expected, but can we bring back the trigger={['click']}
on this component, too?
- keep queryEditors immutable during active state - add unsavedQueryEditor to store all active changes - refactor each component to subscribe the related unsaved editor state only
0b1fa32
to
dfb30fc
Compare
@eschutho I updated the commit. Can you review the update? thanks! |
@eschutho @michael-s-molina Can we merge the PR? |
Ephemeral environment shutdown and build artifacts deleted. |
…e#20877) * perf(sqllab): Rendering perf improvement using immutable state - keep queryEditors immutable during active state - add unsavedQueryEditor to store all active changes - refactor each component to subscribe the related unsaved editor state only * revert ISaveableDatasource type cast * missing trigger prop * a default of an empty object and optional operator (cherry picked from commit ddb5fcdc0cb597c2fd947d39a05055c2949c29a7)
apache#20877)" This reverts commit f77b910.
…ble state (apache#20877)"" This reverts commit 8b1886a.
SUMMARY
The main rendering in SqlLab is managed by the
queryEditors
state from redux(state machine).Each queryEditor state has been updated whenever an editor configuration has updated.
Since most components observes entire queryEditor state not specific attributes, any queryEditor updates trigger multiple repainting even if no visual changes impacted.
For example, when a user types any single character in the ace(sql) editor, it triggers the update for
selectedText
value in the active queryEditor state. This single change will trigger the following components repainted (though this change won't impact the left and bottom panels at all)This unrelated repainting job causes the performance delay especially when table list is humongous.
The delay can be found in the following performance analysis due to the unnecessary repainting/redux post processes.
This commit fixes this performance issue by optimizing observers in each component to subscribe only related items.
To minimize the regression issue from existing persistence state, this commit keeps the existing
queryEditors
state but make it immutable during the tab is active and only updates when the tab is switched. It introducesunsavedQueryEditor
state which stores all these active changes.With this update, the page rendering performance improved 3.5x faster(from 4.5s to 1.3s) and verified all unnecessary tasks cleaned.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before (4.5s):
slow-sqllab.mov
After (1.3s):
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION