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

A linear algorithm for _.flatten. #573

Merged
merged 1 commit into from
Apr 30, 2012
Merged

A linear algorithm for _.flatten. #573

merged 1 commit into from
Apr 30, 2012

Conversation

mhansen
Copy link
Contributor

@mhansen mhansen commented Apr 27, 2012

Gives massive speedups on _.flatten for large, deep arrays, see http://jsperf.com/underscore-flatten-quadratic.

The trouble was the .concat call, which constructs a new array each time it's called. Swapping it out for the .push method makes it linear.

I also added a performance test for flatten, to catch this in case this comes up again.

Massive speedups on _.flatten for large, deep arrays.
jashkenas added a commit that referenced this pull request Apr 30, 2012
A linear algorithm for _.flatten.
@jashkenas jashkenas merged commit 78a9e48 into jashkenas:master Apr 30, 2012
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

Successfully merging this pull request may close these issues.

2 participants