3 ms·
Are 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
by paulgb 3y ago
Are 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.