_.min() fails with large input (potentially anything that uses .apply() internally) #578

jeeyoungk opened this Issue Apr 30, 2012 · 5 comments


None yet
2 participants

In Chrome / Firefox (haven't tested in IE, but I'm assuming the same result will occur), this code raises exception.

var x = []
for(var i =0;i < 1000000;i++){x.push(i)}
_.min(x); // ERROR

In Chrome, it gives "RangeError: Maximum call stack size exceeded". In Firefox, it gives "RangeError: arguments array passed to Function.prototype.apply is too large".

This is because .apply() can only take limited amount of parameters, depending on the browser, 65k in webkit's case - https://bugs.webkit.org/show_bug.cgi?id=80797


jashkenas commented Apr 30, 2012

I believe this is intentional. If you'd like to ensure that Math.min is never used, you can pass an iterator argument to _.min. Do you think this should be changed?

Is Math.min more efficient than say, iterating the data and calculating the min manually? Unless that's the case, I think this is bit arbitrary limitation of _.min() function.


jashkenas commented Apr 30, 2012

I believe it is. You can run a JSPerf.com to test it if you like. If it does turn out to be much more efficient, would you still like to change it?

I wonder how many other people are having the same problem. I'll think about the possibilities. I'll get back to the test & and more opinion later on, because I'm in a middle of something.

jashkenas closed this in a7215f0 May 9, 2012


jashkenas commented May 9, 2012

Give that commit a try, and see if it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment