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

Package performance and bundle-size #4882

Open
joshblack opened this issue Dec 15, 2019 · 23 comments
Open

Package performance and bundle-size #4882

joshblack opened this issue Dec 15, 2019 · 23 comments
Labels
package: @carbon/react @carbon/react proposal: open This request has gone through triaging. We're determining whether we take this on or not. type: enhancement 💡

Comments

@joshblack
Copy link
Contributor

joshblack commented Dec 15, 2019

In 2020, we want to become more aware and sensitive to the performance of the packages we ship. Overall, this would include focusing on the following areas:

  • The ability to get the overall bundle size of shipped JavaScript and CSS assets for a bundle
  • The ability to track the sizes of files over time
  • The ability to comment on PRs with the reported change in size
  • The ability to test that a package can be tree-shaken / dead-code eliminated
@paul-sachs
Copy link

I think this would be an amazing addition. I've recently noticed that on a simple example of using @carbon/icons-react package (within cra), the bundle was 2.16MB despite only importing a single icon:

image

Looking at the es/index.js, looks like each is labeled as PURE but seems like that's not doing enough.

@joshblack
Copy link
Contributor Author

@paul-sachs most like that's related to some kind of webpack configuration issue, if you install and use it from a stock CRA it will get tree-shaken so something is going on in the build and optimization pipeline 🤔

@paul-sachs
Copy link

@joshblack this was a pretty clean cra app (created a few days ago) with some customize-cra to enable less loading along with bundle analyzer. I was surprised as well. Maybe you're right, might be just something weird about my config.

@baeharam
Copy link
Contributor

@paul-sachs Did you solve that issue?

@doublepithre
Copy link

@baeharam check the code for any ".../lib/..." imports that was the case for me

@baeharam
Copy link
Contributor

baeharam commented May 30, 2020

@doublepithre I use typescript and when I use full import, type cannot be inferred. Any idea?

Could not find a declaration file for module '@carbon/icons-react/es/search/16'. '/Users/haram/haram/github/my-project/node_modules/@carbon/icons-react/es/search/16.js' implicitly has an 'any' type.
If the '@carbon/icons-react' package actually exposes this module, consider sending a pull request to amend 'https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/carbon__icons-react`

@doublepithre
Copy link

doublepithre commented May 30, 2020

@baeharam
Copy link
Contributor

@doublepithre
I already installed, but when I use full import, it cannot infer type. My stackoverflow question

@JoshuaTruscott
Copy link

@doublepithre thank you!! this was the same issue I was having, removed the imports and my bundle size has been significantly reduced. 👍

@brandones
Copy link
Contributor

@baeharam I filed #9540 about the type problems for subpackage imports.

@brandones
Copy link
Contributor

I just filed #9651 (creating a Babel plugin to transform standard imports into subpackage imports), which I think would do wonders for developer experience, as well as resolve (/moot) the type problems for subpackage imports.

@cortopy
Copy link

cortopy commented Feb 16, 2022

Just bumped into this issue really bad. This is a bundle analysis for a Gatsby app. It's not just that tree shaking isn't working, in my case each icon brings a whole bucket of icons with it. Each bucket is 150-175K. This is humongous. I got several MB of icons and many many chunks

image

@doublepithre solution worked brilliantly for me

import ChevronUp24 from '@carbon/icons-react/es/chevron--up/24';

@joshblack
Copy link
Contributor Author

Hi @cortopy, generally when all of the icons are included there is some part of a project that imports from lib.

Here's a quick way that we test to make sure icons are able to be tree-shaken: #6602 (comment)

If there are steps to reproduce the issue that you're experiencing, let me know! Happy to take a look and see what's going on.

@cortopy
Copy link

cortopy commented Feb 24, 2022

Thanks @joshblack . In my case I didn't have any import of lib but changing to long es imports worked. I only had around 10 imports so it was easy for me to do.

The only thing different I had was import type { CarbonIconType } from '@carbon/icons-react'. I wouldn't think that's the issue since it's just a type but don't know if that's the issue

@tay1orjones tay1orjones moved this to 🕵️‍♀️ Triage in Design System Sep 20, 2022
@sstrubberg sstrubberg moved this to Triage in Roadmap Dec 16, 2022
@sstrubberg sstrubberg added the proposal: open This request has gone through triaging. We're determining whether we take this on or not. label Dec 16, 2022
@tay1orjones
Copy link
Member

tay1orjones commented Dec 19, 2022

The ability to get the overall bundle size of shipped JavaScript and CSS assets for a bundle
The ability to comment on PRs with the reported change in size

For these two, I like the idea of adding dangerJS and using it to get prod/PR bundle sizes and compare them, then comment on PRs.

React uses this approach. They're using pre-minified bundles though. We'll need to minify ours before compressing with gzip and report on each.

Ideally this would apply for every package in the monorepo, but we could start with just @carbon/react.

I also think compiling @carbon/styles sass to css and tracking that bundle size could be useful as well.

@sstrubberg sstrubberg added the package: @carbon/react @carbon/react label Dec 19, 2022
@sstrubberg
Copy link
Member

The risk of not doing this. We risk bloating the bundle size without knowing about it.
Lower-level infrastructure.
Test coverage would be a higher priority as an example.

@sstrubberg sstrubberg moved this from Triage to Icebox in Roadmap Jan 10, 2023
@abdonrd
Copy link
Contributor

abdonrd commented May 17, 2023

Is the effort to reduce the size of packages still on?

Trying to use tools like Bundlephobia to measure... Show build errors:
https://bundlephobia.com/package/@carbon/styles

Screenshot 2023-05-17 at 12 10 06 PM

Instead of the bundle size like other packages:
https://bundlephobia.com/package/lit

@abdonrd
Copy link
Contributor

abdonrd commented May 19, 2023

In our Nuxt project, the top 5 dependencies are:

300M	@carbon
200M	@ibm
 38M	typescript
 34M	@babel
 20M	carbon-components

Using:

"@carbon/icons-vue": "^10.49.1",
"@carbon/styles": "^1.29.0",
"@carbon/web-components": "^1.27.0",
"@ibm/plex": "^6.3.0",
// ...

@tay1orjones
Copy link
Member

Is the effort to reduce the size of packages still on?

Just to clarify, this issue is for beginning to analyze, report, and track bundle size information. It's not an effort to reduce the bundle size (yet).

Once we begin tracking the bundle size(s) and ensuring tree-shaking works on every PR, a workstream could spawn to work on evaluating if and how bundle size could be reduced.

Trying to use tools like Bundlephobia to measure... Show build errors:

I'm not sure why bundlephobia fails to build the package, pastelsky/bundlephobia#795

@abdonrd
Copy link
Contributor

abdonrd commented Dec 13, 2023

@tay1orjones thanks for the update!

@abdonrd
Copy link
Contributor

abdonrd commented Dec 13, 2023

I see it works with other measure tools like pkg-size:

Screenshot 2023-12-13 at 9 47 50 AM Screenshot 2023-12-13 at 9 48 02 AM Screenshot 2023-12-13 at 9 50 28 AM Screenshot 2023-12-13 at 9 52 11 AM

@SimeonC
Copy link

SimeonC commented Sep 10, 2024

With Vite (rollup) I was doing bundle optimisation and experimenting with changing all the paths from the generated files import { IconName } from '@carbon/icons-react' to the /es/IconName import and using the individual imports allows tree-shaking.

I compared 3 different approaches and settled on the vite-plugin way (published here; https://github.com/tablecheck/frontend/tree/main/packages/vite-import-massager-plugin)

  • Default way of just import from '@carbon/icons-react'
  • Changing my code with a vite plugin to transform imports pre-build to '@carbon/icons-react/es/IconName' specific Imports
  • Changing the index.js file in node_modules to import the individual files and not the generated bundle files.
Approach Tree Shaking Build Speed
Default No Normal
Vite Plugin Yes Normal
node_modules Yes Very Slow

Screenshot of carbon icons import in the main bundle.

CleanShot 2024-09-10 at 09 50 05

@tay1orjones
Copy link
Member

@SimeonC Last year we had a similar report about the default approach:

If you'd like to continue discussing this please open a new issue. This one here is just regarding adding tooling for tracking our own bundle size(s) in PRs and over time.

@tay1orjones tay1orjones removed the epic label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: @carbon/react @carbon/react proposal: open This request has gone through triaging. We're determining whether we take this on or not. type: enhancement 💡
Projects
Status: Later 🧊
Development

No branches or pull requests