Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Similarly as in https://github.com/jashkenas/underscore/pull/2496, I found that flatten function can be optimized by swapping the order of checks in logical expression in line 500 (the second check is false most of the time). I provide the screenshot with the results for unit tests which performance got improved (on V8 4.4 engine). Inputs are the same as in unit tests in the repository and performance is tested with Benchmark.js library.
The code for tests can be download from: https://s3.eu-central-1.amazonaws.com/underscorebenchmark/benchmarks2.zip
To run the tests, just call
I am maybe wrong, but can isArrayLike(value) check be omitted here?