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

[Fleet] Reduce bundle sizes #82160

Closed
jfsiii opened this issue Oct 30, 2020 · 3 comments
Closed

[Fleet] Reduce bundle sizes #82160

jfsiii opened this issue Oct 30, 2020 · 3 comments
Labels
Team:Fleet Team label for Observability Data Collection Fleet team technical debt Improvement of the software architecture and operational architecture

Comments

@jfsiii
Copy link
Contributor

jfsiii commented Oct 30, 2020

Goal

Aim for individual bundles under 250k uncompressed.

Why

Spending a long time parsing/compiling code can heavily delay how soon a user can interact with your site. The more JavaScript you send, the longer it will take to parse and compile it before your site is interactive.

-- Web Fundamentals docs

Reducing the uncompressed size of JS (in total & per-file) greatly reduces the work for the browser and provides a better experience for the user. There are variables like network & CPU speed but, generally, sending 1 500k bundle is worse than 2 250k or 5 100k bundles.

We're currently loading JS that's not strictly required. e.g. we load all plugin JS used anywhere when the overview page is hit. Ideally, we'd load less JS but we can at least make smaller chunks of work for the browser. Less JS might come from these changes or might happen later.

Current status

/app/ingestManager loads ~275kb compressed or 1.8MB parsed JS in production (e.g. cloud staging)

Screen Shot 2020-10-30 at 10 18 43 AM

The plugin entrypoint ingestManger.plugin.js is about 400k
Screen Shot 2020-10-30 at 10 48 41 AM

With ingestManger.chunk.2.js roughly half of that and an uncompressed size over 1MB
Screen Shot 2020-10-30 at 10 23 11 AM

What's in the bundles

  1. Generate a stats.json file via node scripts/build_kibana_platform_plugins.js --profile --focus=ingestManager more info
    * --dist gives is what we'll send to users, but it loses a bit of detail about the source, so I omit it while iterating on approaches
  2. Put that in a tool like
    * https://chrisbateman.github.io/webpack-visualizer/
    * https://github.com/webpack-contrib/webpack-bundle-analyzer

How move dependencies into another bundle/chunk

TL; DR: Lazy load with await import() Use React.lazy or similar approach on client side. We should eventually have a standard way of doing this, but we don't need to come up with one before we start. More at Keep Kibana fast

Analysis & options

ingestManager.plugin.js 385k

stats screenshots Screen Shot 2020-10-30 at 11 23 32 AM Screen Shot 2020-10-30 at 11 23 43 AM
- export const fullAgentPolicyToYaml = (policy: FullAgentPolicy): string => {
+ export const fullAgentPolicyToYaml = async (policy: FullAgentPolicy): Promise<string> => {
+ const { safeDump } = await import('js-yaml');

ingestManager.chunk.2.js (chunk.1 in dev) 1.1M

stats screenshots Screen Shot 2020-10-30 at 11 54 06 AM Screen Shot 2020-10-30 at 11 54 08 AM Screen Shot 2020-10-30 at 12 31 43 PM
  • 45% is from three dependencies d3, react-use, react-markdown
  • 20% (400k) is because the dependencies for each public/applications/sections/ingest_manager component are in the same bundle.
    • Switch the overview page to lazy-load the individual Integrations, Agents, etc section
@jfsiii jfsiii added the Team:Fleet Team label for Observability Data Collection Fleet team label Oct 30, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/ingest-management (Team:Ingest Management)

@ph ph added the technical debt Improvement of the software architecture and operational architecture label Oct 30, 2020
@jfsiii
Copy link
Contributor Author

jfsiii commented Apr 26, 2021

#95855 (comment) says goal is under 100k for ingestManager.plugin.js fleet.plugin.js

@jen-huang jen-huang changed the title [Ingest Manager] Reduce bundle sizes [Fleet] Reduce bundle sizes Apr 27, 2021
@joshdover
Copy link
Contributor

Superseded by #95863

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Fleet Team label for Observability Data Collection Fleet team technical debt Improvement of the software architecture and operational architecture
Projects
None yet
Development

No branches or pull requests

4 participants