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

Add code splitting to the client bundles in triggers_actions_ui plugin #64315

Closed
mshustov opened this issue Apr 23, 2020 · 11 comments · Fixed by #65678
Closed

Add code splitting to the client bundles in triggers_actions_ui plugin #64315

mshustov opened this issue Apr 23, 2020 · 11 comments · Fixed by #65678
Assignees
Labels
performance Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@mshustov
Copy link
Contributor

triggers_actions_ui.plugin.js bundle size is 2.7Mb at the moment

node scripts/build_kibana_platform_plugins.js --dist --no-examples --profile
ls -lh x-pack/plugins/triggers_actions_ui/target/public/

This bundle is loaded eagerly whenever a user opens the Kibana app.
We could decrease the plugin size drastically if add code-splitting and lazy loading for the plugin. The most obvious candidates for optimization are UI components used in actionTypeRegistry that could be loaded on-demand.
Related discussion #64179

@mshustov mshustov added performance Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) labels Apr 23, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-alerting-services (Team:Alerting Services)

@mikecote mikecote added this to To-Do 7.8 (Ordered by priority) in Make it Action Apr 27, 2020
@gmmorris gmmorris moved this from To-Do 7.8 (Ordered by priority) to To-Do 7.7.1 (Ordered by priority) in Make it Action May 4, 2020
@gmmorris gmmorris self-assigned this May 4, 2020
@gmmorris
Copy link
Contributor

gmmorris commented May 4, 2020

Picking this up as a time-boxed (a half day or so) investigation to figure out what's causing such an unexpected size and to report back to the team.
We will decide how proceed once we understand where the size is coming from.

@gmmorris
Copy link
Contributor

gmmorris commented May 4, 2020

Looking at the bundle created when building the Triggers UI is primarily made up of 3 "packages":

  1. Our actual UI components
  2. Lodash
  3. Brace (the JSON editor we use)

In the PR I've put together I changed the Email action so that the Params and Connector field components are loaded lazily. Looks like everything still works same as before except the files have been chunked up such that the email components only get loaded when the Flyout is actually rendered.
Repeating this work for all Action and Alert types should make the initial load mildly smaller- about 95k less.

In addition we should be able to lazy load the routes to the alerting UI - this should defer loading about 200k until the user actually navigates into the UI.

All in all once complete - this work should reduce the size loaded when Kibana boots up by just shy of 300k.

I'm going to talk to Platform - as it doesn't make sense to include Lodash, Brace, FP-TS and IO-TS when talking about how big Triggers UI is - as I assume it's loaded by other parts of Kibana too and hopefully we're not loading that for each plugin 😱

@gmmorris
Copy link
Contributor

gmmorris commented May 4, 2020

To see the details for yourself you can use: https://chrisbateman.github.io/webpack-visualizer/

Drop in the attached stats.json
stats.json.zip

@mshustov
Copy link
Contributor Author

mshustov commented May 4, 2020

Lodash, Brace, FP-TS and IO-TS when talking about how big Triggers UI is - as I assume it's loaded by other parts of Kibana too and hopefully we're not loading that for each plugin 😱

We are. Only brace is in shared deps atm. lodash is another big guy, but different plugins use different versions, so we cannot alias it.

@gmmorris
Copy link
Contributor

gmmorris commented May 4, 2020

Lodash, Brace, FP-TS and IO-TS when talking about how big Triggers UI is - as I assume it's loaded by other parts of Kibana too and hopefully we're not loading that for each plugin 😱

We are. Only brace is in shared deps atm. lodash is another big guy, but we different plugins use different versions, so we cannot alias it.

Cool, thanks Mikhail.
Any advice on how we could still reduce the size then? Lodash is about 20% of our bundle :/

@gmmorris gmmorris moved this from To-Do 7.7.1 (Ordered by priority) to In Progress in Make it Action May 4, 2020
@mshustov
Copy link
Contributor Author

mshustov commented May 5, 2020

I'm surprised that brace included in your bundle. It's used in es_ui_shared plugin, which is shared across plugins. However, I noticed it isn't in your case. Since you import code from src/plugins/es_ui_shared/static which breaks sharing logic.
@elastic/es-ui Could you move es_ui_shared/static to es_ui_shared/public as it's recommended in the migration guide?
@spalger FYI. It's not compatible with the current optimizer logic and can break #64843

@gmmorris we will fix the problem with lodash as soon as update the version. that will allow us to use the same version in the whole Kibana #7537
Meantime, you can use lazy loading for react components in sections and components folders.

@cjcenizal
Copy link
Contributor

@restrry I've created #65301 to track removing the static directory but it's blocked by ongoing work. The soonest we could act on this is probably 1-2 weeks.

@gmmorris
Copy link
Contributor

gmmorris commented May 6, 2020

Cool cool 👍
I've sorted out the sections and components and am just trying to finish off some of the interaction of this with siem as it broke their usage of us (they register React components with us so we can inject theirs into ours where needed).

looking at the es_ui_shared/static issue - am I right that we can't avoid that until @cjcenizal completes the work mentioned above? 🤔

@mshustov
Copy link
Contributor Author

mshustov commented May 6, 2020

am I right that we can't avoid that until @cjcenizal completes the work mentioned above? 🤔

yeah, this optimization can wait.

@spalger
Copy link
Contributor

spalger commented May 6, 2020

Any advice on how we could still reduce the size then? Lodash is about 20% of our bundle :/

I recommend not using lodash :)

@gmmorris gmmorris moved this from In Progress to In Review in Make it Action May 12, 2020
@gmmorris gmmorris moved this from In Review to Done (Ordered by most recent) in Make it Action May 13, 2020
@kobelb kobelb added the needs-team Issues missing a team label label Jan 31, 2022
@botelastic botelastic bot removed the needs-team Issues missing a team label label Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
No open projects
Make it Action
  
Done (Ordered by most recent)
Development

Successfully merging a pull request may close this issue.

6 participants