I'm hunting down a problem in a recursive algorithm I wrote.
This algorithm would throw a RangeError: Maximum call stack size exceeded
(in Chrome) Error on some inputs. But the call stack I tracked down was only about 6k-9k in size.
This test (from this SO answer) indicates a maximum call stack size of about 42k in Chrome.
After running some tests, I found, that having arguments on the recursive functions seems to lower the available call stack size:
With arguments: call stack size exceeded on ~31k (Chrome, ~15k on Edge)
var recursionA = function(a, b) {
count++;
if (count < 100000) {
recursionA(a, b);
}
}
Without arguments: call stack size exceeded on ~42k (Chrome, ~16.5k on Edge)
var recursionB = function() {
count++;
if (count < 100000) {
recursionB();
}
}
- Can anyone explain, why the available call stack size is significantly lower, when the function is called with arguments.
- Since my recursive function would require 2 arguments: How can I utilize the max call stack size of the browser?
- Are there other factors that can potentially reduce the available call stack size?