Skip to content

[code-infra] Add bundle size monitor #1791

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

Merged
merged 34 commits into from
May 29, 2025
Merged

[code-infra] Add bundle size monitor #1791

merged 34 commits into from
May 29, 2025

Conversation

Janpot
Copy link
Member

@Janpot Janpot commented Apr 28, 2025

Porting the bundle size monitor from core. This establishes a baseline. This bundles each entrypoint with its dependencies. Bundles are stored in S3 for comparison. Peer dependencies are ignored. To inspect the created bundles run

pnpm size:why

examples:

Screenshot 2025-05-09 at 10 06 31

Screenshot 2025-05-15 at 15 01 28

Copy link

netlify bot commented Apr 28, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit f1f2b1f
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6838276971600b00080e20b6
😎 Deploy Preview https://deploy-preview-1791--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mui-bot
Copy link

mui-bot commented Apr 28, 2025

Bundle size report

🚫 No bundle size snapshot found for base commit 4285f43.

Total Size Change: +1.45MB(0.00%) - Total Gzip Change: +491KB(0.00%)
Files: 41 total (41 added, 0 removed, 0 changed)

@base-ui-components/reactparsed:${\tiny{\color{orangered}▲}}$+308KB(new) gzip:${\tiny{\color{orangered}▲}}$+92.6KB(new)
@base-ui-components/react/menuparsed:${\tiny{\color{orangered}▲}}$+114KB(new) gzip:${\tiny{\color{orangered}▲}}$+37.8KB(new)
@base-ui-components/react/context-menuparsed:${\tiny{\color{orangered}▲}}$+113KB(new) gzip:${\tiny{\color{orangered}▲}}$+36.9KB(new)
@base-ui-components/react/selectparsed:${\tiny{\color{orangered}▲}}$+111KB(new) gzip:${\tiny{\color{orangered}▲}}$+37.1KB(new)
@base-ui-components/react/popoverparsed:${\tiny{\color{orangered}▲}}$+86.1KB(new) gzip:${\tiny{\color{orangered}▲}}$+29KB(new)
@base-ui-components/react/navigation-menuparsed:${\tiny{\color{orangered}▲}}$+84.9KB(new) gzip:${\tiny{\color{orangered}▲}}$+28.5KB(new)
@base-ui-components/react/tooltipparsed:${\tiny{\color{orangered}▲}}$+63.9KB(new) gzip:${\tiny{\color{orangered}▲}}$+21.6KB(new)
@base-ui-components/react/preview-cardparsed:${\tiny{\color{orangered}▲}}$+59.2KB(new) gzip:${\tiny{\color{orangered}▲}}$+20.2KB(new)
@base-ui-components/react/dialogparsed:${\tiny{\color{orangered}▲}}$+52.5KB(new) gzip:${\tiny{\color{orangered}▲}}$+17.6KB(new)
@base-ui-components/react/alert-dialogparsed:${\tiny{\color{orangered}▲}}$+52.2KB(new) gzip:${\tiny{\color{orangered}▲}}$+17.5KB(new)

Show 31 more bundle changes

@base-ui-components/react/number-fieldparsed:${\tiny{\color{orangered}▲}}$+28.9KB(new) gzip:${\tiny{\color{orangered}▲}}$+10.3KB(new)
@base-ui-components/react/tabsparsed:${\tiny{\color{orangered}▲}}$+26.6KB(new) gzip:${\tiny{\color{orangered}▲}}$+9.15KB(new)
@base-ui-components/react/toastparsed:${\tiny{\color{orangered}▲}}$+26.4KB(new) gzip:${\tiny{\color{orangered}▲}}$+9.52KB(new)
@base-ui-components/react/sliderparsed:${\tiny{\color{orangered}▲}}$+24.5KB(new) gzip:${\tiny{\color{orangered}▲}}$+9.22KB(new)
@base-ui-components/react/accordionparsed:${\tiny{\color{orangered}▲}}$+23.1KB(new) gzip:${\tiny{\color{orangered}▲}}$+7.98KB(new)
@base-ui-components/react/radio-groupparsed:${\tiny{\color{orangered}▲}}$+20.4KB(new) gzip:${\tiny{\color{orangered}▲}}$+7.76KB(new)
@base-ui-components/react/menubarparsed:${\tiny{\color{orangered}▲}}$+19.7KB(new) gzip:${\tiny{\color{orangered}▲}}$+7.34KB(new)
@base-ui-components/react/toolbarparsed:${\tiny{\color{orangered}▲}}$+19.6KB(new) gzip:${\tiny{\color{orangered}▲}}$+6.85KB(new)
Base UI checkboxparsed:${\tiny{\color{orangered}▲}}$+18.7KB(new) gzip:${\tiny{\color{orangered}▲}}$+7.01KB(new)
@base-ui-components/react/checkboxparsed:${\tiny{\color{orangered}▲}}$+18.7KB(new) gzip:${\tiny{\color{orangered}▲}}$+7.01KB(new)
@base-ui-components/react/collapsibleparsed:${\tiny{\color{orangered}▲}}$+18.1KB(new) gzip:${\tiny{\color{orangered}▲}}$+6.28KB(new)
@base-ui-components/react/scroll-areaparsed:${\tiny{\color{orangered}▲}}$+15.8KB(new) gzip:${\tiny{\color{orangered}▲}}$+5.63KB(new)
@base-ui-components/react/radioparsed:${\tiny{\color{orangered}▲}}$+15KB(new) gzip:${\tiny{\color{orangered}▲}}$+5.7KB(new)
@base-ui-components/react/switchparsed:${\tiny{\color{orangered}▲}}$+14.6KB(new) gzip:${\tiny{\color{orangered}▲}}$+5.59KB(new)
@base-ui-components/react/toggle-groupparsed:${\tiny{\color{orangered}▲}}$+13.8KB(new) gzip:${\tiny{\color{orangered}▲}}$+5.36KB(new)
@base-ui-components/react/fieldparsed:${\tiny{\color{orangered}▲}}$+13.8KB(new) gzip:${\tiny{\color{orangered}▲}}$+5.28KB(new)
@base-ui-components/react/checkbox-groupparsed:${\tiny{\color{orangered}▲}}$+12.1KB(new) gzip:${\tiny{\color{orangered}▲}}$+4.77KB(new)
@base-ui-components/react/inputparsed:${\tiny{\color{orangered}▲}}$+10.9KB(new) gzip:${\tiny{\color{orangered}▲}}$+4.38KB(new)
@base-ui-components/react/toggleparsed:${\tiny{\color{orangered}▲}}$+8.99KB(new) gzip:${\tiny{\color{orangered}▲}}$+3.66KB(new)
@base-ui-components/react/utilsparsed:${\tiny{\color{orangered}▲}}$+8.17KB(new) gzip:${\tiny{\color{orangered}▲}}$+3.15KB(new)
@base-ui-components/react/progressparsed:${\tiny{\color{orangered}▲}}$+7.48KB(new) gzip:${\tiny{\color{orangered}▲}}$+3.04KB(new)
@base-ui-components/react/meterparsed:${\tiny{\color{orangered}▲}}$+7.36KB(new) gzip:${\tiny{\color{orangered}▲}}$+3.03KB(new)
@base-ui-components/react/avatarparsed:${\tiny{\color{orangered}▲}}$+7.22KB(new) gzip:${\tiny{\color{orangered}▲}}$+2.89KB(new)
@base-ui-components/react/fieldsetparsed:${\tiny{\color{orangered}▲}}$+5.93KB(new) gzip:${\tiny{\color{orangered}▲}}$+2.47KB(new)
@base-ui-components/react/formparsed:${\tiny{\color{orangered}▲}}$+5.74KB(new) gzip:${\tiny{\color{orangered}▲}}$+2.46KB(new)
@base-ui-components/react/separatorparsed:${\tiny{\color{orangered}▲}}$+4.28KB(new) gzip:${\tiny{\color{orangered}▲}}$+1.84KB(new)
@base-ui-components/react/use-renderparsed:${\tiny{\color{orangered}▲}}$+3.84KB(new) gzip:${\tiny{\color{orangered}▲}}$+1.67KB(new)
@base-ui-components/react/unstable-use-media-queryparsed:${\tiny{\color{orangered}▲}}$+1.95KB(new) gzip:${\tiny{\color{orangered}▲}}$+941B(new)
@base-ui-components/react/merge-propsparsed:${\tiny{\color{orangered}▲}}$+1.55KB(new) gzip:${\tiny{\color{orangered}▲}}$+764B(new)
@base-ui-components/react/unstable-no-ssrparsed:${\tiny{\color{orangered}▲}}$+1.27KB(new) gzip:${\tiny{\color{orangered}▲}}$+681B(new)
@base-ui-components/react/direction-providerparsed:${\tiny{\color{orangered}▲}}$+644B(new) gzip:${\tiny{\color{orangered}▲}}$+390B(new)

Details of bundle changes

Generated by 🚫 dangerJS against f1f2b1f

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 30, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 6, 2025
Copy link

pkg-pr-new bot commented May 6, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@base-ui-components/react@1791

commit: f1f2b1f

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 8, 2025
return {
id: entrypoint,
import: entrypoint,
externals,
Copy link
Member Author

@Janpot Janpot May 20, 2025

Choose a reason for hiding this comment

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

This is unnecessary if @base-ui-components/react adds an export condition for ./package.json. Then we can just return entrypoint from this function and the bundle size monitor will infer the externals from the peer dependencies. Right now it has no real way to find the package.json location reliably for a module. (besides using a custom resolver)

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind exporting package.json. Can you do it in this PR or prefer me to open a new one?

Copy link
Member Author

Choose a reason for hiding this comment

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

had it before in this PR, will bring it back.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've seen that many packages adopted this convention, it will become obsolete though once findPackageJSON becomes more stable

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 20, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 21, 2025
@michaldudak michaldudak added scope: code-infra Specific to the code-infra product and removed scope: code-infra labels May 22, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 22, 2025
@Janpot Janpot requested a review from michaldudak May 22, 2025 12:55
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 27, 2025
@Janpot Janpot requested a review from colmtuite as a code owner May 28, 2025 09:25
@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels May 28, 2025
@michaldudak
Copy link
Member

I checked https://bundlephobia.com/package/@base-ui-components/[email protected] and it shows drastically different values. Do you have any idea where this difference might come from?
One reason could be measuring a different version (alpha.8 vs. the latest master), but it's hard to believe we almost doubled the library size since the latest release.

@Janpot
Copy link
Member Author

Janpot commented May 28, 2025

bundlejs also measures around 100KB gzipped

Bundle size is 316 kB -> 100 kB (gzip)

In general we should be wary of bundlephobia stats. They for instance also measure the data grid at 47B.

Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

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

All right, let's see it in action.

@Janpot
Copy link
Member Author

Janpot commented May 29, 2025

Also working on an experimental vite version of the bundle size monitor, it shows similar results to the webpack one within a tolerance of ~1KB.

bundlephobia is built with package-build-stats. Looks like they also do a webpack build and analyze the stats.json, with externals from peer dependencies. Haven't looked any deeper yet how they calculate their sizes.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label May 29, 2025
@Janpot Janpot merged commit eb0c901 into mui:master May 29, 2025
22 checks passed
atomiks pushed a commit to atomiks/base-ui that referenced this pull request May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance scope: code-infra Specific to the code-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants