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

Remove unreasonably slow alternatives to lodash functions #400

Open
valadaptive opened this issue Jun 29, 2024 · 0 comments
Open

Remove unreasonably slow alternatives to lodash functions #400

valadaptive opened this issue Jun 29, 2024 · 0 comments

Comments

@valadaptive
Copy link

valadaptive commented Jun 29, 2024

I haven't comprehensively looked over the list of alternatives, but just as an example, one of the listed alternatives to _.last(numbers) is:

[].concat(numbers).pop()

It is even listed twice since it "works with undefined/null":

// Native (works even with potentially undefined/null)
[].concat(undefined).pop()

While this code is certainly clever, it's also slow. It creates an entire copy of the source array in memory, and if someone uses this code in a loop, it could easily go quadratic.

I believe that code like this which "prematurely pessimizes" common operations should not be listed as an example.

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

1 participant