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

feat: move ace-editor and mathjs to async modules #10837

Merged
merged 11 commits into from
Sep 15, 2020
Merged

Conversation

ktmud
Copy link
Member

@ktmud ktmud commented Sep 11, 2020

SUMMARY

Follow up on #10831, move brace and mathjs to async modules so that the initial page load for dashboards most pages can be faster.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

On a dashboard page, brace loads only after users add a markdown widget to dashboard:

brace-async-load

Optimized bundle config further helps reduce the overall bundle size:

new-bundle

new-load-time

Initial page load time with production assets and without cache was reduced by 30% (9.8s -> 6.9s in Fast 3G network).

On Explore and CRUD page, brace and mathjs are also loaded on demand.

TEST PLAN

  • Manual testing + a couple of cypress tests

Expected behaviors:

  1. Dashboards should not load brace.js and mathjs by default.
  2. Entering edit mode in dashboards with Markdown widgets should preload brace.js, even when users haven't started editing the markdown.
  3. Dashboards with Line charts should load mathjs automatically.
  4. In explore view, mathjs will load only for charts that support annotation layers.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@codecov-commenter
Copy link

codecov-commenter commented Sep 11, 2020

Codecov Report

Merging #10837 into master will increase coverage by 2.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10837      +/-   ##
==========================================
+ Coverage   59.32%   61.34%   +2.02%     
==========================================
  Files         776      380     -396     
  Lines       37060    24086   -12974     
  Branches     3310        0    -3310     
==========================================
- Hits        21986    14776    -7210     
+ Misses      14891     9310    -5581     
+ Partials      183        0     -183     
Flag Coverage Δ
#cypress ?
#python 61.34% <ø> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
superset/db_engine_specs/presto.py 81.61% <0.00%> (-0.68%) ⬇️
...set-frontend/src/dashboard/util/injectCustomCss.js
...board/util/getSelectedChartIdForFilterScopeTree.js
.../src/SqlLab/components/EstimateQueryCostButton.jsx
...uperset-frontend/src/components/TooltipWrapper.jsx
...frontend/src/dashboard/actions/dashboardFilters.js
...src/dashboard/components/DeleteComponentButton.jsx
...end/src/dashboard/util/getKeyForFilterScopeTree.js
.../src/explore/components/FilterDefinitionOption.jsx
...nd/src/dashboard/util/getComponentWidthFromDrop.js
... and 371 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 045335a...21616b3. Read the comment docs.

@ktmud ktmud force-pushed the async-mathjs branch 2 times, most recently from a9f4ae0 to ee48ef6 Compare September 11, 2020 17:00
@ktmud ktmud marked this pull request as draft September 11, 2020 19:03
@ktmud ktmud force-pushed the async-mathjs branch 2 times, most recently from cce2701 to c6aa954 Compare September 11, 2020 20:43
@ktmud ktmud marked this pull request as ready for review September 11, 2020 21:18
@ktmud ktmud force-pushed the async-mathjs branch 2 times, most recently from 2582cb9 to bfc0805 Compare September 11, 2020 22:07
Copy link
Member Author

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

@kristw @etr2460 @graceguo-supercat This is ready for review. Would you mind taking a look?

// height is specified.
(height && (
<div style={{ width, height }}>
{showLoadingForImport && <Loading position="floating" />}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is for displaying a loading spinner while the async module is still loading:

E.g.:

Snip20200911_25

Normally users wouldn't see this because most places we used the AsyncEsmComponent have on-demand preloading.

output.filename = '[name].[chunkhash].entry.js';
output.chunkFilename = '[name].[chunkhash].chunk.js';
} else {
output.filename = '[name].[chunkhash].entry.js';
output.chunkFilename = '[chunkhash].chunk.js';
Copy link
Member Author

Choose a reason for hiding this comment

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

Don't add names to chunkFiles (they are just single digit numbers anyway).

'redux',
'react-redux',
'react-hot-loader',
'react-select',
'react-sortable-hoc',
'react-virtualized',
'react-table',
'react-ace',
Copy link
Member Author

Choose a reason for hiding this comment

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

react-ace itself is quite small.

name: 'brace',
test: /\/node_modules\/(brace|react-ace)\//,
priority: 40,
},
Copy link
Member Author

Choose a reason for hiding this comment

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

Different brace modes/themes now load separately and asynchronously.

maxLines={inModal ? 1000 : this.props.maxLines}
onChange={this.onAceChange.bind(this)}
onChange={this.onAceChangeDebounce}
Copy link
Member Author

Choose a reason for hiding this comment

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

Added debounce to text inputs in Explore view's Datasource editor.

editorProps={{ $blockScrolling: true }}
enableLiveAutocompletion
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this prop according to a console warning from Ace.

prefix: string,
callback: (error: null, wordList: object[]) => void,
) => {
if ((session.getMode() as TextMode).$id === `ace/mode/${mode}`) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Enable completion for only the related language.

*/
export default function AsyncAceEditor(
aceModules: AceModule[],
{ defaultMode, defaultTheme, defaultTabSize = 2 }: AsyncAceEditorOptions = {},
Copy link
Member Author

Choose a reason for hiding this comment

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

Set default tabSize for all AceEditor. Previously there were some places where tabSize was not set and would default to 4.

@mistercrunch
Copy link
Member

calp

Copy link
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

LGTM! The cleanup this brings, and the performance improvement, are both appreciated.

Left some general questions & comments you're already addressing, so thanks for that.

const AnnotationLayer = AsyncEsmComponent(
() => import('./AnnotationLayer'),
// size of overlay inner content
() => <div style={{ width: 450, height: 368 }} />,
Copy link
Member

Choose a reason for hiding this comment

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

Could/should these be based on % values or use a flexbox layout (using the built-in "stretch" features) to avoid hard-coding these dimensions?

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal here is to make sure the popover renders at the right position so that the left caret always points to the popover trigger when the content of the popover is fully loaded. We wouldn't want the popover to "stretch" since there is no way to update its position after it was re-rendered.

'moment',
'jquery',
'core-js.*',
'@emotion.*',
'd3.*',
'd3',
'd3-(array|color|scale||interpolateformat|selection|collection|time|time-format)',
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

||interpolateformat => |interpolate|format

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, just wow... Thanks for spotting this!

@ktmud ktmud merged commit 0129c42 into apache:master Sep 15, 2020
@ktmud ktmud deleted the async-mathjs branch September 15, 2020 21:12
@ktmud ktmud mentioned this pull request Nov 12, 2020
6 tasks
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
Follow up on apache#10831, move brace and mathjs to async modules so that the initial page load for dashboards most pages can be faster.
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.38.0 labels Mar 12, 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/XXL 🚢 0.38.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants