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

Reduce bundle size #88

Open
v1vendi opened this issue Sep 5, 2019 · 4 comments
Open

Reduce bundle size #88

v1vendi opened this issue Sep 5, 2019 · 4 comments

Comments

@v1vendi
Copy link

v1vendi commented Sep 5, 2019

Hello! I saw that you race for minified size, and I have tried several options to minify the bunde for modern browsers for about 15%:

  • create a let x = true and set all settings from contextTypes: true to contextTypes: x - saves ~20b of minified code
  • rewrite getStatics method to arrow function - 16b of minified code
  • forEach in loop - around 25b
  • caching repeating keys (defaultProps, displayName, propTypes) also gains around 20b
  • exporting function after declaration saves around 30b

Unminified souce is also reduced by 400 bytes

Should I provide a PR for all of this or some points are useless?)

@v1vendi
Copy link
Author

v1vendi commented Sep 5, 2019

moving from const to let can also save some bytes, if you agree)

@eps1lon
Copy link
Contributor

eps1lon commented Sep 6, 2019

moving from const to let can also save some bytes, if you agree)

Did you measure the reductions after transpiling the code?

@v1vendi
Copy link
Author

v1vendi commented Sep 6, 2019

That's fun, for current rollup setup build size increases for all 3 of bundles (cjs, default and minified), as it builds to ES5. So the question now is should we optimize for older or for newer browsers. Decision is for you :)

@v1vendi
Copy link
Author

v1vendi commented Sep 6, 2019

Some more info - when I build the project as is, the minified file size is 6312b. When I add optimizations, file size grows to 6459b, but if I add a browserslist config with (for example) chrome > 49 I get 6181b.

Also this optimizations will be used by a large number of developers, who build hoist-non-react-statics with their own bundles
So I'd still consider applying this micro-optimizations, even though they increase bundle size for old browsers and make some parts of code a bit more complex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants