func5000 – how far does your UA get?

Can your browser handle a call depth of 5000 functions? Look here and see how far you get with various JS engines:

func5000.htm

I'd really like to know if there is a hard-coded limitation or if it depends on system speed and memory, for example. Discussion is open in the comments 🙂

Advertisements

38 thoughts on “func5000 – how far does your UA get?

  1. With Opera I get "function 4998 running"With firefox I get "- died when trying to call function 1000, error was "too much recursion""

  2. In a fairly recent Firefox 3 build, the hard-coded 1000 limit mentioned earlier is no longer present and has been replaced with some amount of dynamic sizing (not complete, because if you actually let it expand to fill RAM you're swapping hard at the limit, hurting overall system performance). Using the following testcase, I get 228816 as the iteration depth:

    ,<script>%20var%20o;%20window.onload%20=%20function()%20{%20o%20=%20document.getElementById("out");%20recur(1);%20};%20function%20recur(n)%20{%20o.textContent%20=%20n;%20recur(n%20+%201);%20}%20</script>%20Iteration%20depth:%20<span%20id="out">(none,%20test%20failed%20to%20run)

    Basically the depth is unlimited for all practical purposes, unless you're writing in continuation-passing style or you're using recursion instead of proper, unambiguous-performance looping constructs for iteration. (Can you guess what I think of languages which force iteration to be written to appear at the surface as stack-exhausting recursion? For any simple algorithm, the code to implement it shouldn't be required to look like it performs worse than it actually does.)

  3. "function 2503 running" on Opera 9.24.8816.0, 512MB RAM. Sometimes 2504."function 4998 running" on Opera 9.50.9665.0IE 6.0.2900.2180 reports '- died when trying to call function 1124, error was "Out of stack space"'Fx 2.0.0.10 reports: '- died when trying to call function 1000, error was "too much recursion"'Safari 3.0.3 reports: '- died when trying to call function 98, error was "Maximum call stack size exceeded."'PS: May I suggest uploading it as test.html.gz ?

  4. Opera 9.24.8816.0 Iteration depth: 3341Opera 9.50.9665.0 Iteration depth: 9998FX 2.0.0.10 Iteration depth: 1000Safari 3.0.3 Iteration depth: 99By putting a "window.status = n" in front of "recur(n + 1)", it's possible to see the result in IE6, too: I get an iteration depth of 1124

  5. Only 498 in Safari 3 on Windows :OError: "Maximum call stack size exceeded."But the smallest result I could get was under Adobe Air(uses WebKit, well, at least a very old version from mid 06 or so), after 98 calls it stopped.

  6. On 9.24.8816 (Win Vista; 2 GB RAM): "function 2501 running" (~ between 2499 and 2502). IE 7: "- died when trying to call function 2548, error was "Nicht genügend Arbeitsspeicher."" (german for: "not enough memory").

  7. Safari 3.0.4 (5523.10) on Mac OS X 10.5.1:- died when trying to call function 498, error was "Maximum call stack size exceeded."Opera 9.24 Build 3707 on Mac OS X 10.5.1:function 2498 running

  8. 4998 with Opera 9.5.9665 and 192MBOn a slightly similar note, try the TC in this bug to watch Safari and IE6 die, Opera and IE7 throw an exception and FF handle it just fine.

  9. Platform: Win32System: Windows XPJava: Sun Java Runtime Environment version 1.6TEST RESULTS, sorted by timeOpera 9.50 9665

    function 4998 running

    Firefox 2.0.0.9

    - died when trying to call function 1000, error was "too much recursion"

    Netskape Navigator 9.0b1

    {...full code displayed and... } /* this is function 4835 */

    Safari 3.0.3

    function 707 running

    MSIE 5.01

    - died when trying to call function 384

    MSIE 5.5

    function 2086 running

    MSIE 6

    - died when trying to call function 690

    MSIE 7

    - died when trying to call function 690
  10. Opera 9.5.9665 -function 4998 runningMinefield/3.0b2pre -function 5000 running – FINISHED! 5000 function calls took 423msOpera 9.24.8816 -function 2498 runningIE 7 — died when trying to call function 2550, error was "Out of memory"Windows XP/SP2 – 256MB Ram

  11. On Fedora 7 (1GB RAM, ~1350 MHz Athlon):Opera 9.5 alpha: function 4998 runningFirefox 3 beta 1: completed all 5000.Epiphany (running Gecko 1.8.1.9, equiv. to Firefox 2.0.0.9): stopped at 1000 with "too much recursion"Konqueror 3.5.8: – died when trying to call function 998, error was "Exceeded maximum function call depth."On Windows XP (768 MB RAM, 2.93 GHz Celeron):Safari 3.0.4: – died when trying to call function 498, error was "Maximum call stack size exceeded"IE7: – died when trying to call function 2550, error was "Out of memory"No change on IE7 when I closed some more apps to free up memory.

  12. 2.2Mhz single core AMD Athlon 64, 2 GiB ram, winxpsp2:kestrel (b9624): function 4998 runningmerlin (9.24): function 2501 runningop 7.52 (b3808): function 1672 runningie6: – died when trying to call function 1124, error was "Out of stack space"saf 3.0.4b: – died when trying to call function 498, error was "Maximum call stack size exceeded."ff2.0.0.10: – died when trying to call function 1000, error was "too much recursion"ff3.0b1: function 5000 running – FINISHED! 5000 function calls took 264msUsing waldo's test:kestrel (b9624): Iteration depth: 9998saf 3.0.4b: Iteration depth: 499ff2.0.0.10: Iteration depth: 1000ff3.0b1: Iteration depth: 228816

  13. Originally posted by Opera 9.50.9656:

    FAILED (seems stresstest script did not even parse.. though please wait a few seconds..)function 4998 running

    Originally posted by Firefox 3 Beta 1:

    FAILED (seems stresstest script did not even parse.. though please wait a few seconds..)function 5000 running – FINISHED! 5000 function calls took 1228ms

    Originally posted by IE7:

    – died when trying to call function 2550, error was "Out of memory"

    WinXP Pro SP2 384MB 2.2 GHzFirefox's average time was around 550ms after refreshing.just submitted http://browsershots.org/http://files.myopera.com/hallvors/blog/func5000.htmMS IE 6.0 on Windows 2000 crashed (oops… I didn't mean too!); died at 1124Safari 3.0.3 for Windows 2000 died at 98, call stack size exceeded.Firefox 2.0.0.9 for Windows 2000 died at 1000 – too much recursionOpera 9.24 for Windows XP – function 2504 running

  14. Opera 9.5.1678 (x64)-First message was:"FAILED (seems stresstest script did not even parse.. though please wait a few seconds..)"-Then.."function 4998 running"..I hope we can reach the 5000 mark soon! Looks like we have some catching up to do (at least a little bit…ff3).Firefox 2.0.0.10 (x64)'- died when trying to call function 1000, error was "too much recursion"'Firefox 3 (Win32)"function 5000 running – FINISHED! 5000 function calls took 313ms"IE7 (Win32)' – died when trying to call function 2550, error was "Out of memory"'It looks like most are hard coded I guess. Opera 9.2x seems to be getting a few different results, while 9.5x is getting constants like IE and FF did.

  15. "function 5000 running – FINISHED! 5000 function calls took 213ms"firefox 3b1 (amd x2 (s939) @2100mhz, 2gb ddr @230mhz 2-2-2-5 1T)others failed, seems to me clearly, that FF 3 does this test the best

  16. Ubuntu 7.10 (AMD Athlon64 3200+, 1GB RAM):- Opera 9.24: "function 2500 running"- opera-9.50-20071109.6-shared-qt.i386-1662: "function 4998 running"- Firefox 2.0.0.10: "- died when trying to call function 1000, error was "too much recursion""- Wine-emulated IE6: "- died when trying to call function 500, error was "Not enough memory.""

  17. I also got ~2500 for Opera 9.24 and <5000 for Opera 9.5…Didn't test other browsers.Comment: This doesn't test recursion, though. This just tests how many different functions can be nested. A situation where you only use function recursion instead of loops shouldn't have exactly the same constraints as nested individual functions, imho. I'm just very bad at functional recursion so I can't really test it…Also it would theoretically be possible to optimize for functions with identical function body (which you are using a ton of). So… er… maybe you should create them with Function(), give them some different number to crunch and see what happens? ;D

  18. _Grey_ : did I say it was testing recursion? I was trying to figure out the limits of chaining different function calls (which may or may not be the same limit the engine has for recursion).Also, the function bodies are not quite identical – they contain different numbers in the string that is passed to the DOM and in the name of the next function called. I don't write JS compilers myself but I'd be quite impressed if anyone could optimise for similar functions with such differences.The various test results seem to show that most browsers have hard-coded call depth limits. The grand exception is Firefox 3, which calculates the limit dynamically. I wonder if it can give JS that much resources and still avoid a rogue script slowing down or freezing your entire system.

  19. >> I wonder if it can give JS that much resources and still avoid a rogue script slowing down or freezing your entire system.Firefox pops up a dialog to the user when scripts run for too long, asking if the user wants to stop the script or let it continue. But if a script wants to slow down or freeze a browser, there are much easier ways of doing it. In every browser I've ever tried, freezing the browser up indefinitely was very easy (when purposely trying to do it). I would be very impressed if Opera was the first one to put serious effort into overcoming this.

  20. Well, I can tell you Opera has put some serious effort into that problem ;), for example can you put JavaScript into a never-ending loop likewhile(true);and observe how the UI stays fairly responsive. Because of this we have not implemented the "slow script" warning dialog found in Firefox and (I believe) also in IE. I'm not saying that you can't make Opera's UI freeze with JS tricks but I do think you have to work a bit harder..

  21. Good news with Opera 10.60!

    function 5000 running – FINISHED! 5000 function calls took 188ms

    Opera 10.60- died when trying to call function 16382, error was "Maximum recursion depth exceeded"Google Chromium 6.0.423.0 (48614) Ubuntu:- died when trying to call function 13059, error was "undefined"Firefox 3.6.3- died when trying to call function 3000, error was "too much recursion"test it for yourself:http://kyleabaker.com/temp/func20000.html.zip

  22. James Long writes:Opera 10.60 on Fedora 13 (x86_64):function 5000 running – FINISHED! 5000 function calls took 170msFirefox 3.6.7 on same machine:- died when trying to call function 3000, error was "too much recursion"Sorry, Firefox fans…Opera wins again.Distressing news for faithful Opera fans, however…Chrome (just downloaded 64-bit rpm for this test):function 5000 running – FINISHED! 5000 function calls took 364msThe only consolation was that Opera performed the test over twice as fast with several tabs open, while Google Chrome was tested while being the only app running with only 1 tab open.I didn't feel like booting into Windows to test IE, but I doubt it would get any farther than Firefox, if even that far.

  23. Anonymous writes:Long live James Long! If opera had a god surely james would be worthy enough to control the power that opera harnesses.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s