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

Frontend: Code split the plugin for improved performance #764

Open
Tracked by #737
leeoniya opened this issue Sep 12, 2024 · 1 comment · May be fixed by #768
Open
Tracked by #737

Frontend: Code split the plugin for improved performance #764

leeoniya opened this issue Sep 12, 2024 · 1 comment · May be fixed by #768
Assignees
Labels
enhancement New feature or request

Comments

@leeoniya
Copy link

Hello! 👋

Whilst auditing Grafana javascript payloads we've noticed that your Grafana app plugin is not taking advantage of code splitting. This is resulting it a large amount of Javascript being preloaded before the Grafana application can render anything. We're aware applications grow over time and generally we're not great at keeping on top of this but we would really appreciate it if you could put some time into code splitting this app plugin to help us reduce the amount of javascript code we're loading up front.

The following are worth considering when taking on this task:

  1. The module.js is the entrypoint. It's worth keeping in mind that the smaller this file is the less effect it has on the performance of Grafana as a whole during the app preload phase which is currently render blocking.
  2. Rename your module.ts to module.tsx and take advantage of Suspense, lazy, and webpacks dynamic import to lazy load your apps rootPage and (if it has one) its config page too.
  3. If your app contains additional routes and pages they are likely the quickest way to reduce bundle size further by lazy loading them.
  4. Any component registry (i.e. an array of objects that contain components) should be considered a target for code splitting with Suspense / lazy to further reduce bundle size.
  5. Any components used with the plugin ui extensions api should be considered a target for code splitting with Suspense and lazy to remove them from the bundled module.js file.

Below are two examples of Grafana plugins that have recently been code split or are in the process of being code split. The motions are generally the same for all app plugins as the module.js revolves mostly around the AppPlugin class. These should help give you a better understanding of what's involved:

Further information:

@leeoniya
Copy link
Author

btw, this is what we're seeing when loading up an empty dashboard on an ephemeral instance, to give you an idea of potential impact on overall load times:

https://ephemeral1511182192959leeoniy.grafana-dev.net/d/cdwx3aa48mvb4d/empty?from=now-6h&to=now&timezone=browser

Image

@leeoniya leeoniya added the enhancement New feature or request label Sep 12, 2024
@gtk-grafana gtk-grafana linked a pull request Sep 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants