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

[APM] Reduce initially loaded bundles by 98% #191658

Merged
merged 21 commits into from
Sep 3, 2024

Conversation

tonyghiani
Copy link
Contributor

@tonyghiani tonyghiani commented Aug 28, 2024

📓 Summary

Closes #191600

Moving on invocation site the dynamic import to instantiate the apm locator and registering the embeddable removed the async import on the biggest APM js chunks.

In practice, we passed from loading ~900kb of JS to ~10kb, with a total reduction of about ~16% of all the code loaded by Kibana for any page.

There is also deeper code splitting for the APM routes to only load specific features when required on while using the APM app.

Before After
Screenshot 2024-08-28 at 17 58 59 Screenshot 2024-08-28 at 17 59 30

Mandatory celebration GIF

@obltmachine
Copy link

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@tonyghiani tonyghiani added release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team labels Aug 29, 2024
@tonyghiani
Copy link
Contributor Author

/ci

@tonyghiani tonyghiani marked this pull request as ready for review August 30, 2024 13:49
@tonyghiani tonyghiani requested a review from a team as a code owner August 30, 2024 13:49
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

@botelastic botelastic bot added the ci:project-deploy-observability Create an Observability project label Sep 2, 2024
Comment on lines 45 to 50
const DiagnosticsImportExport = dynamic(() =>
import('./import_export_tab').then((mod) => ({ default: mod.DiagnosticsImportExport }))
);
const DiagnosticsApmDocuments = dynamic(() =>
import('./apm_documents_tab').then((mod) => ({ default: mod.DiagnosticsApmDocuments }))
);
Copy link
Member

Choose a reason for hiding this comment

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

IMHO we don't need to go overboard here. Can't we load the diagnostics page in a single async chunk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not prob, I can revert this to a single chunk removing the imports. To keep in mind, this will load an extra ~10kb of minified code before it gets really used in that async chunk, which is not a big deal but still worth noticing.

Copy link
Member

Choose a reason for hiding this comment

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

10% increase in what scenario? the user that loads the diagnostics page loads 10% extra JavaScript compared to splitting the diagnostic page in separate chunks, or also for anyone who e.g. uses the embeddable or loads Kibana at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A user landing on the diagnostics page loads the JS for all the available tabs at once, even if the user only visits the Summary tab. With the lazy loading I used, every tab chunk (~2.5kb) is loaded only when visiting the tab. Should we still keep it split in this case?

Copy link
Member

Choose a reason for hiding this comment

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

nah let's just do one chunk, 2.5kb is not worth the network overhead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screen.Recording.2024-09-02.at.09.34.00.mov

Copy link
Member

Choose a reason for hiding this comment

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

btw, same for the others, I think we can find a better balance between loading too much upfront and loading too many small chunks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reduced code splitting to where it only has the biggest impact now. The entry point for other pages is not impacted (load only apm.plugin.js)

Copy link
Contributor

@cauemarcondes cauemarcondes left a comment

Choose a reason for hiding this comment

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

LGTM

@tonyghiani
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@crespocarlos crespocarlos left a comment

Choose a reason for hiding this comment

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

Great stuff. Thanks for this.

@kibana-ci
Copy link
Collaborator

kibana-ci commented Sep 3, 2024

💚 Build Succeeded

  • Buildkite Build
  • Commit: cc36d28
  • Kibana Serverless Image: docker.elastic.co/kibana-ci/kibana-serverless:pr-191658-cc36d285658e

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
apm 1866 1867 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
apm 3.5MB 3.5MB +57.2KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
apm 39.8KB 39.9KB +136.0B
Unknown metric groups

async chunk count

id before after diff
apm 36 53 +17

History

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

@tonyghiani tonyghiani merged commit b7a909f into elastic:main Sep 3, 2024
23 checks passed
@tonyghiani tonyghiani deleted the 191600-optimize-apm-bundles branch September 3, 2024 12:46
@kibanamachine kibanamachine added v8.16.0 backport:skip This commit does not require backporting labels Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting ci:project-deploy-observability Create an Observability project release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[APM] Optimize initial load bundles
8 participants