4 ms·
I never liked lodash, even when when it was new. These days I just laugh when people tell how great it is. Useful? Sure. But if you care about performance and
by beebeepka 3y ago
I never liked lodash, even when when it was new. These days I just laugh when people tell how great it is.
Useful? Sure. But if you care about performance and simplicity, just spend a day or two writing your own versions of the things that you need. Or, if rolling home made is not to your liking, go with ramda.
Edit: downvote vall you want but at least have a look at lodash internals just in case. What an overcomplicated mess. It's old, really old.
- K0balt 3y agoHe’s rewriting from scratch in typescript.
- SparkyMcUnicorn 3y agoLooking at the internals is often why I choose to use it. It catches edge cases I might not think of, and the performance tradeoffs have been negligible to none. I don't use it for everything, and definitely try to use native and/or narrower scope methods when it makes sense, but it's saved me a lot of time and headache throughout the years.
- paulgb 3y agoAre there functions where the performance is significantly worse than what you could write on your own? Not a rhetorical question. I don’t use lodash but as a primarily non-JS dev I’ve referred to the source some times when I’m writing JS as a reference for the idiomatic way to do simple things. I’ve found some weird things, like isEmpty is technically O(n), but this turns out to be a limitation of JavaScript rather than a lodash issue.
- eyphka 3y agoThere are a couple of weird things in my experience, like the old implementation of zip, but by and large it was mostly either restrictions of js itself or browser implementations of js. Lodash has and still is a good standard / reference for these simple operations imo.
- mediumdeviation 3y agoI don't think isEmpty is O(n) except in the case where the object is a prototype[1] - I assume that's one of those weird JS edge cases - otherwise it does what you expect, which is to iterate with a for-in loop and return on the first iteration, so it is O(1). [1]: https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L11493 https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L114...
- paulgb 3y agoSurprisingly, even if you return at the first iteration, it’s O(n) on V8 just to construct the iterator.
- ChrisMarshallNY 3y ago> at least have a look at lodash internals just in case. I think that's the issue. The author seems to agree with you, and is rewriting it. I don't use JS or Lodash, so I have no feedback on the particulars of this instance. However, I am in the final phase of a "Declare bankruptcy, hit reset" rewrite of the app I'm developing, and I'm really, really glad that I did it. I did encounter many of the same issues, as I proceeded on the rewrite, but I was prepared, and I feel I handled them far more elegantly than the original. But that was a luxury that I had, as we are not doing the MVP thing. If you are dealing with a shipped app, it's quite a challenge, to do the bankruptcy thing.