documentcloud/underscore — pull request #573 by mhansen (2012-04-27 14:02:16+00:00)
Title: A linear algorithm for _.flatten.

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.