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

[Tracking] Reduce install footprint 🐾 #29038

Open
4 of 67 tasks
vanessayuenn opened this issue Sep 3, 2024 · 1 comment
Open
4 of 67 tasks

[Tracking] Reduce install footprint 🐾 #29038

vanessayuenn opened this issue Sep 3, 2024 · 1 comment

Comments

@vanessayuenn
Copy link
Contributor

vanessayuenn commented Sep 3, 2024

πŸ§‘β€πŸ€β€πŸ§‘ Who: @JReinhold and @ndelangen

This is a tracking issue for the Reduce install footprint 🐾 project. The purpose of this issue is to keep tracking of the overall status of the project and tasks, and plan everything around it.

See also #29072 which is a spike we'll be doing as part of this project to investigate how to move Storybook towards publishing ESM-only packages.

πŸ“’ Want to help?

Make sure you read this issue thoroughly to understand what we want to achieve and how.
Do not ask to be assigned to certain tasks, just do them. We won't "reserve" anything to potential contributors, that system rarely work. Help out with what you want, and report findings in this issue, eg. if you've identified potential optimisations in a package. If you open pull requests with your work make sure to reference this issue and tag @JReinhold.

⚠️ Problem

One of the biggest complaints about Storybook is that it's a big and heavy dependency to add to your project. There are muliple ways to interpret the frustration, but one of the most impactful improvements we can make is to reduce the install size of the core Storybook experience.

Throughout the current Storybook 8 releases we've already managed to cut the size significantly, eg. via #27039 and #28519. But there is plenty more work to be done - especially outside the core package - that will enable us to shrink Storybook even further.

🏁 Goals

The high-level goals of this project is to:

  1. Reduce the install size of "the core Storybook experience". That is, the packages that are included in a normal init process, such as storybook, the builders (Vite/Webpack), the renderers (React, Svelte, etc.) and the default addons.
  2. ... this includes reducing the dependency graph of mentioned packages, to speedup installation.
  3. Set long-term baselines and goals that will keep us in check, ensuring we don't regress the install-size later.
  4. Build and set up tooling to support these goals. We'll try to find ways that make it easier to maintain lean packages and reduce their footprint. This includes easy-to-access bundle and package analysis tools and reporters.
  5. Identify changes that require a major version bump. This project will conclude before the next major version of Storybook, so we can't make those changes now, but we can prepare them so they are ready when we're closer to the next major release.

This means we are not focusing on performance improvements nor reducing the size of a built Storybook. We still love those improvements, but they are not the major focus here.

πŸ“š Resources

πŸ“Š Spreadsheet with package stats

πŸ”¬ Methodology

Storybook is a complex mesh of over 30 packages, therefore analysing "Storybook's" install size will be tackled from two angles:

  1. E2E tests aka sandboxes: Storybook sandboxes represent real-world, minimal projects with Storybook installed. Storybook support countless project configurations, eg. A NextJS project, or a Vite-based Vue project. By initialising Storybook a top these minimal projects, we get a sense of what impact Storybook has on the overall node_modules size and the amount of dependencies added to the project. The upside of this perspective is that it directly focuses on the experience our users get. The downside of this approach - as with most E2E tests - is that it can be "flaky" because a lot of outside factors can impact the project's install size and dependency count. It's also a coarse metric, detecting significant size increases in sandboxes doesn't really help us identify where the increase is coming from. This brings us to...
  2. Unit tests aka packages: Each individual Storybook package will have its own metric on install size and dependency graph. Measuring and detecting size increases at the package-level makes it a lot easier to pinpoint the cause of it. But laser-focusing on packages in isolations can lead to work that makes little difference to the end-user, because they don't use the Storybook packages in isolation. Eg. removing a big dependency from @storybook/react-vite doesn't help if that dependency is still installed by @storybook/core.

Therefore we must keep both metrics in mind, to ensure we improve the experience for the end-user while still getting actionable results on the lower level.

We'll use a breadth-first approach when doing the optimisations across the packages. At the start of the project all, the integration packages have a single task (which also applies to the core): Identify potential optimisations. We'll do that first across all the packages on a high-level, to identify common patterns and find big wins first. This ensures that we don't laser focus on eg. removing 15 KB from @storybook/react when we could instead have removed 12 MB from @storybook/vue3-vite.
With that said, there are already known big wins in the core packages that might get a higher priority than looking into some of the integration packages.

There are many approaches and tools to optimising package's size and dependencies and it's not a one-size-fits-all. https://e18e.dev/guide/cleanup.html is a good primer on how to approach it. At a high-level we'll:

  1. Use https://pkg-size.dev to identify and monitor the size of the packages and their dependencies
  2. Use https://npmgraph.js.org to identify and monitor the packages' dependency graph
  3. Use ESBuild's metafiles that are produced when building all the packages, to identify and monitor the packages' internal structure and bundled dependencies.

We can take @storybook/core as an example:

  1. https://pkg-size.dev/@storybook/[email protected] shows that there are two major esbuild dependencies significantly contributing to the size. Can we replace it? See Migrate from esbuild to jiti for preset handlingΒ #29082
  2. https://npmgraph.js.org/?q=@storybook/[email protected]#select=exact%3Aexpress%404.20.0 shows that express (among others) contribute to a big part of the dependency graph. Can we replace it? See Migrate from express to polkaΒ #29083
  3. ESBuild's metafiles for @storybook/core (not currently public) shows that Prettier makes up a big part of the bundled output. Can we replace it, or remove it? See Minimize the bundling of prettier in @storybook/coreΒ #29084

🚩 Milestones

πŸ“ˆ Baselines and Bechmarks

See spreadsheet detailing all the packages.

Tasks

  1. JReinhold
  2. JReinhold

πŸ”§ Optimisations

This section includes all the actual package optimisations that we want to make. The list is highly dynamic and should change a lot during the project.

Existing work that needs triage

  1. ci:normal maintenance
    ndelangen
  2. ci:normal dependencies
    valentinpalkovic

πŸ“¦ Core Packages

Package replacements

  1. core dependencies
  2. dependencies
    43081j JReinhold
  3. ci:normal dependencies maintenance
    shilman
  4. ci:normal core dependencies
    43081j JReinhold
  5. Tracking help wanted performance issue
  6. JReinhold
  7. ci:normal dependencies
    JReinhold

Architectural changes

  1. core dependencies
    JReinhold
  2. ndelangen
  3. ndelangen

🧩 Integration Packages

Builders

@storybook/builder-vite

@storybook/builder-webpack5

Renderers

@storybook/react

@storybook/vue3

@storybook/web-components

Frameworks

@storybook/react-vite

@storybook/react-webpack5

@storybook/nextjs

@storybook/experimental-nextjs-vite

@storybook/angular

@storybook/vue3-vite

@storybook/vue3-webpack5

@storybook/sveltekit

@storybook/svelte-vite

@storybook/web-components-vite

@storybook/web-components-webpack5

Addons

@storybook/addon-docs

@storybook/blocks

@storybook/addon-interactions

@storybook/addon-actions

@storybook/test

@storybook/addon-controls

@storybook/addon-measure

@storybook/addon-outline

@storybook/addon-backgrounds

@storybook/addon-toolbars

@storybook/addon-viewport

@storybook/addon-onboarding

πŸ› οΈ Supporting Tooling

Ideally we'd want to set up some tooling that allows to easily inspect package and dependency sizes, to make it easier to optimise these areas. It's still TBD what shape or form these could take.

🌟 Essential tooling

  1. JReinhold

✨ Nice-to-have tooling

  1. webpro

Related: evanw/esbuild#3909

🀷 Misc

🎁 Wrap up

πŸ’₯ Breaking optimisations

  1. BREAKING CHANGE components core

πŸ’– Nice-to-haves

@JReinhold JReinhold changed the title Reduce install footprint Tracking: Reduce install footprint Sep 9, 2024
@JReinhold JReinhold changed the title Tracking: Reduce install footprint Tracking: Reduce install footprint Sep 9, 2024
@JReinhold JReinhold changed the title Tracking: Reduce install footprint Tracking: Reduce install footprint 🐾 Sep 9, 2024
@JReinhold JReinhold changed the title Tracking: Reduce install footprint 🐾 [Tracking] Reduce install footprint 🐾 Sep 9, 2024
@JReinhold
Copy link
Contributor

JReinhold commented Sep 12, 2024

Based on the baseline calculations, I think it's fair to skip the following packages along with @storybook/addon-essentials for now, because they are "tiny" compared to the rest of the packages here:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

2 participants