-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
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
Do not reinvent the wheel. Outsource utility functions. #430
Conversation
Relevant: #306 |
We only need a small part of what they provide, and we really care about keeping the library tiny. What is the total library size before and after this change? |
Notice that I am not including the entire "lodash.isplainobject": "^3.2.0",
"lodash.mapvalues": "^3.0.1",
"lodash.pick": "^3.1.0" |
Before:
After:
|
You are not using the
With this in place, |
That said, it doesn't matter if |
@gajus but what's the point of replacing it? it does the same thing and it just makes redux bigger |
|
The size trade-off does not seem worthy. |
One thing to consider is that many people use lodash. By depending on lodash it may actually decrease total size on modern builds with dedupe. Aaron On Sat, Aug 8, 2015 at 4:42 PM, tacone notifications@github.com wrote:
|
It may not matter to you, but it is one of the factors people consider choosing a library. It is also how they tell “frameworks” from “microlibraries”. Even for marketing purposes, we don't want to give an impression we're a framework, because we're just not. |
Gzipped size before this change: 1957. This is almost 3x size increase. I'm pretty sure we're unlikely to discover edge cases in I understand where your concern is coming from. In fact, if you look back in the history, depending on Lodash individual modules is how this library started. However, if we can be 3x smaller at the cost of maintaining three tiny utility functions, we'll do it. Thank you for your input! |
I know this is closed and I completely agree with the size tradeoff decision. What I don't understand though is how the difference can be so big! Why does:
have so much more overhead than:
(and similarly for the other 2 methods) |
Same thing I encountered with my flux implementation. Using just flattenDeep and mapValues increased my min/gz size by five times :( |
The thing is, lodash pushes all of these standardization utility functions that carry a lot of overhead. @gaearon's decision is natural for a scenario like this. |
So out of curiosity I looked into another way to include lodash with a custom
This resulted in the following two files:
These files include dozens of other utility functions that the included functions depend on in the lodash implementation, thus the size bloat (which looking back now is what @edge was referring to). The functions include things like:
So yeah, that's definitely not happening. |
Well, lodash does add the overhead and I am struggling too in my libs with that issue. But what we all do not consider is that lodash is the market leader and if not already, most project will use it. Overhead will be minimal if the main project uses those lodash functions anyways. |
In a contrast, if every lib will NOT use lodash and maintain own functions - they are not helping to make lodash more popular and though we are not helping in general. Lets see the BIG PICTURE! |
It's cool and great to use lodash from a larger library that actually depends on non-trivial functions, but it feels like a crime to go from being 2K to 5K for no other reason than |
isPlainObject looks very compact by now https://github.com/lodash/lodash/blob/master/lodash.js#L8352 |
But it definitely looks like a crime when lib is so small like redux. It requires to be very idealistic and optimistic to use lodash functions in this cases. I think though we need to push lodash forward to reach at some point a smaller overall footprint of the applications if they all rely on lodash. |
I debated removing lodash from https://github.com/substantial/updeep but ended up putting it back in because of some performance gain. I didn't want to maintain those things, but it does add a pretty large file size overhead. I still ended up removing some (particularly curry, so I could use a faster, more ramda-like version) |
Lodash is working very hard to support people that want the consistency of the library but don't use all the sugar. This will allow people to have near-same file size without maintaining their own fork. You will also be able to reduce the size further using a couple of lines in the webpack config to do some module replacement. These changes should be landing soon, and I hope this can be revisited at that time. |
@kof Yes, |
As @phated wrote we're working on it. Once v4 lands the size should be comparable (within a kb or so) of what you're doing now. @mindjuice Thanks for the help by the way :/ |
@jdalton A passive aggressive class act as always! Don't ever change! For me there is no "big issue". Redux doesn't use lodash. I don't use lodash, and the libraries I use don't use lodash, so why would I open an issue in lodash? |
@mindjuice While you may not use lodash, redux has lodash in its dev-deps graph and until mid-June had lodash as a core dependency :) |
@mindjuice you need a bit more of idealistic thinking) @jdalton We need to improve the size of each function in lodash. I don't think there is any project out there using even half of lodash. Increasing an overall size in favor of lower size of each function should be an acceptable tradeoff. Also I would love to see just one way of including lodash functions. Right now there is a good chance to have the same function included from different build types more than once. |
lodash v4 is modern first – dropping support for older enviros (use es5/6-shim for them). We've also ensured there's a path available for further reducing the size through webpack or browserify module aliases. For example going forward you'll be able to swap FWIW with the current WIP lodash v4 + redux is clocking in at |
@jdalton totally acceptable! |
I'm glad to hear you folks are working on this! |
Here's the WIP branch changes: https://github.com/jdalton/redux/tree/lodash It turns out you could shave a couple bytes off by adding |
Whoops! Good catch :-P |
Digging a bit more by making the check in |
I think we'll drop When React Native 0.10 is out, I think we can bump major version and stop using |
I think the point is that once React Native polyfills it, the |
Got it working, unit tests pass, by replacing both |
The only real reason I feel tempted to use Ramda.js is that they use functions first, then objects (e.g. _.map(x => x+1, array) ). |
Sorry, this is the wrong thread for my comment... I thought it was a 4.0 discussion :/ |
Superseded by #611. |
Wow! Didn't know that @aaronjensen ... ty, cheers! |
pick
,mapValues
andisPlainObject
are standard utility functions available in lodash. Reduce bug surface by using ready made and well tested functions with minimum overhead.