facebookexperimental / Recoil

Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.
https://recoiljs.org/
MIT License
19.58k stars 1.18k forks source link

Library size #1747

Closed javlund closed 2 years ago

javlund commented 2 years ago

Recoil has been steadily growing, and is now about 3,5x larger than v0.0.7:

image

While it's not a huge lib, it's still one of the biggest in my build - and one that has to be loaded up front, as the whole app needs to be wrapped in <RecoilRoot>:

image

Again, it's not gigantic by any means, but it does affect the sizes of the main chunk - to the point where next.js actually starts marking pages depending on it as red instead of green:

image

Looking at issues like https://github.com/facebookexperimental/Recoil/issues/959, I see that I'm not the only one having noticed this. I'm wondering, is work being done to make it more treeshakable perhaps? Or a "light" version like Preact is to React? I'm only using the most basic functionality (RecoilRoot, atom, useRecoilState etc.) so if it was possible to trim the build a bit it would be very much appreciated.

noritheduck commented 2 years ago

Hey javlund, we are adding this to a wish list of work we want to tackle in the future. Thanks for bringing awareness to the large library size.

usercao commented 2 years ago

@noritheduck Do you have a scheduled schedule? Instead of such a vague time in the future, because the size of the library has reached about 250kb, which is several times that of the jotai Library of the same type.

javlund commented 2 years ago

@usercao Yeah, I ended up going with jotai as well for this reason. Would be nice if Recoil got smaller though.

drarmstr commented 2 years ago

There are some things recently which increased the development package size, such as using flow-copy-source which copies the source files completely to provide the Flow type definitions. But, that shouldn't affect the minimized production bundle size. It would be interesting to see the breakdown of the production bundle, how much is due to the HAMT dependency, etc. Looks like bundlephobia.com is currently offline. If the above picture says it is currently 22.9k and HAMT is 15k, then finding a lighter-weight alternative sounds like an interesting place to start. Help investigating and optimizing this is definitely appreciated!

hosembafer commented 1 year ago

Any updates on this?