Skip to content

Conversation

@flash1293
Copy link
Contributor

@flash1293 flash1293 commented Sep 22, 2020

This PR arranges a few imports to make the initial Lens bundle as small as possible. The current Lens bundle loads almost all of the code in the plugin and has >800kb. This PR brings this number down to 270kb (200kb of that being lodash which will be moved to shared bundles anyway: #78100 ).

The loading behavior in this PR is not optimal, but I think it's a good start and can be improved in subsequent PRs

This PR changes a few things:

  • Align individual visualizations: there is an expression.ts file containing renderer and expression function, and a visualization.ts file containing the visualization definition along with editor UI and so on. <name>_visualization.ts is the file being lazily imported, re-exporting both visualization.ts and expression.ts.
  • Move plugin global styles into individual component stylesheets. There were a mixin and some variables, but they weren't actually shared - I moved them into the consuming stylesheets
  • Change the registration of datasources and visualizations from a Promise to a function returning a Promise (basically a lazy promise). This allows to lazily load the visualizations and datasources when either the embeddable or the editor is collecting them. The logic for this was already in place for resolving start services, it's just calling the function before resolving the promise now
  • Move the expression function/renderer registration as well as the visualization definition into a dynamic import in the registered function for each visualization and the datasource.
  • Lazily load the editor frame component plus child components (they were only used in a single place anyway)
  • Introduce a single module re-exporting all visualizations and datasources from a single place and using that for the lazy import to prevent a burst of individual modules loading at the same time.

@flash1293 flash1293 added Feature:Lens v7.10.0 v8.0.0 release_note:skip Skip the PR/issue when compiling release notes labels Sep 22, 2020
@flash1293 flash1293 marked this pull request as ready for review September 22, 2020 15:03
@flash1293 flash1293 requested a review from a team September 22, 2020 15:03
@flash1293 flash1293 requested a review from a team as a code owner September 22, 2020 15:03
@flash1293 flash1293 added the Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// label Sep 22, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

// sass-lint:disable-block indentation, no-color-keywords

// SASSTODO: Create this in EUI
@mixin lnsOverflowShadowHorizontal {
Copy link
Contributor

Choose a reason for hiding this comment

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

Mixin and variable files should still be their own file (even if they're used by only a single component right now). Then what you do is import them in the SASS files that need them instead of relying on a manifest.

@flash1293
Copy link
Contributor Author

@cchaos Reverted mixin and variable files and import them when needed.

@flash1293 flash1293 requested a review from cchaos September 23, 2020 12:50
Comment on lines 1 to 4
@import 'data_panel_wrapper';
@import 'expression_renderer';
@import 'frame_layout';
@import 'suggestion_panel';
@import 'workspace_panel_wrapper';
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry one more thing. Only _index.scss files should be manifest files. You'll need to either revert this back to an index file or put all the imports of these files in their respective JS files.

flex-grow: 1;
}

$lnsPanelMinWidth: $euiSize * 18;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be moved to the variables file.

@flash1293
Copy link
Contributor Author

@cchaos Split scss up into multiple files, no reason to keep an import structure for scss

@wylieconlon Introduced a general re-export file to collapse the async bundles. I added the app bundle as well as this was causing cascading dynamic imports, adding a roundtrip latency. I think we can do better in general, but I think the current state is a pretty good improvement for little work to improve 7.10 bundle sizes.

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

👍 Thanks. Looks like my PR caused some conflicts though. Sorry 😆

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Tested locally and LGTM. I think the description is a little out of date now that it's a single bundle.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

@kbn/optimizer bundle module count

id value diff baseline
lens 560 +86 474

async chunks size

id value diff baseline
lens 995.6KB ⚠️ +962.5KB 33.1KB

distributable file count

id value diff baseline
default 45850 +3 45847

page load bundle size

id value diff baseline
lens 139.6KB -925.9KB 1.0MB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@flash1293 flash1293 merged commit dbef60d into elastic:master Sep 29, 2020
flash1293 added a commit to flash1293/kibana that referenced this pull request Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v7.10.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants