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

[shared-ui-deps] should handle transitive deps? #102697

Closed
Dosant opened this issue Jun 21, 2021 · 7 comments
Closed

[shared-ui-deps] should handle transitive deps? #102697

Dosant opened this issue Jun 21, 2021 · 7 comments
Assignees
Labels
performance Team:Operations Team label for Operations Team

Comments

@Dosant
Copy link
Contributor

Dosant commented Jun 21, 2021

@kbn/shared-ui-deps is used so that most common dependencies across kibana UI are shared between all the plugins and loaded once (e.g. React, EUI, lodash, etc...)

However, when a plugin imports a dependency of one of @kbn/shared-ui-deps dependencies it doesn't get imported from a single @kbn/shared-ui-deps bundle, but it gets bundle into plugin's bundle.

For example:

  • Some plugins imported directly from react-intl instead of @kbn/i18n/react. Fixing this shaved -386.0KB in total from async bundles
  • Another example is react-beautiful-dnd which is a dependency of EUI: react-beautiful-dnd ~400K per each plugin that uses it

Since these transition deps are already bundled into @kbn/shared-ui-deps, when importing such in Kibana directly should they be imported from a shared bundle instead of bundling as a separate instance? If we fix this, the safe would likely be significant (looking at two existing known examples of such mentioned above)

@Dosant Dosant added Team:Operations Team label for Operations Team performance labels Jun 21, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@mistic
Copy link
Member

mistic commented Jun 21, 2021

I think transitive deps should be already bundled. The only thing we need to do if we want to use them is expose them as externals.

@spalger
Copy link
Contributor

spalger commented Jun 21, 2021

Yeah, we need to explicitly choose which packages we want to expose via externals otherwise we'd be bound to the specific version of each transitive dependency used by the packages in @kbn/ui-shared-deps. Exposing transitive dependencies and automatically rewriting all imports for those packages to use ui-shared-deps is as easy as exposing them in two places:

  • with a export const PackageName = require('transitive-dep') in packages/kbn-ui-shared-deps/src/entry.js
  • with a mapping in the externals map at the bottom of packages/kbn-ui-shared-deps/src/index.js

@mistic
Copy link
Member

mistic commented Jun 21, 2021

@Dosant do you think we can consider this closed?

@Dosant
Copy link
Contributor Author

Dosant commented Jun 21, 2021

@Dosant do you think we can consider this closed?

@mistic, I think these changes that @spalger laid out should be at least done for react-intl and react-beautiful-dnd before closing this? Ideally, in the scope of this, we also could identify other packages that could benefit from this? (maybe a script?)

Or are you suggesting this isn't worth pursuing?

@spalger
Copy link
Contributor

spalger commented Jun 21, 2021

I think that instead of sharing react-intl we should rely on ESLint to discourage it's use, but we'll see what the improvement of sharing react-beautiful-dnd is in #102834. I don't think it's clear how we'd write a script to determine what is or isn't worth sharing, but if you wanted to take a stab at it I'd be happy to lend a hand or walk you though how I might do it. Transient dependencies of packages already in ui-shared-deps are definitely a vein of dependencies that would probably be worth discovering and sharing since they're already loaded on every page anyway.

@spalger spalger self-assigned this Sep 28, 2021
@spalger
Copy link
Contributor

spalger commented Sep 28, 2021

In #110558 we split the @kbn/ui-shared-deps package into two, one with the dependencies from NPM and one with the dependencies which are in the source. The @kbn/ui-shared-deps-src package works the same way the old package did by exposing an externals map which forces chosen modules to be overridden with the version from @kbn/ui-shared-deps-*. The @kbn/ui-shared-deps-npm package on the otherhand exposes a DLL which is referenced by the @kbn/ui-shared-deps-src package and all bundles created by the optimizer. This allows any NPM module which is already in that DLL to be linked from the bundles rather than copied into them, effectively handling transitive deps for the vast majority of packages. If there are additional packages we would like to add to that DLL we can do so, but for now I think we're in a good position to close this issue.

@spalger spalger closed this as completed Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Team:Operations Team label for Operations Team
Projects
None yet
Development

No branches or pull requests

4 participants