In Phantomjs, What Is The Function Call Stack Limit?
How many times can a function recursively call itself before breeching PhantomJS javascript engine's call stack limit? Said another way, what is the last possible n printed here f
Solution 1:
I've used your code and ran it in different PhantomJS versions on my PC and my Raspberry Pi 1 running Raspbian.
Platform | Version | Maximum callstack -------------------------------------- Win 8.1 | 2.0.0 | 65277 Win 8.1 | 1.9.8 | 65534 Win 8.1 | 1.9.7 | 65534 Win 8.1 | 1.9.0 | 65534 Win 8.1 | 1.8.2 | 65534 RPi 1 | 2.0.1* | 43547 RPi 1 | 1.9.7 | 65534 RPi 1 | 1.9.0 | 65534
* Development version compiled on March 13 2015 on a Raspberry Pi 2
The following is a more realistic code example, because you're rarely using synchronous and recursive code in a PhantomJS script or on the page.
var n = 0;
functionf() {
console.log(++n);
//f();setTimeout(f, 0);
}
f();
This asynchronous version, which is more likely to be used, has no apparent callstack limit. I stopped the process (v1.9.8 and v2.0.0 on Win 8.1) after about 300,000 iterations (52 minutes). Version 1.9.8 constantly sat at 27.2 MB of memory and v2.0.0 jumped around in the range of 8 to 10 MB of memory.
Post a Comment for "In Phantomjs, What Is The Function Call Stack Limit?"