Novemberborn, Straight lines circle sometime

Maximum Call Stack Size in Modern Day Browsers

I had to write a depth-first tree iterator recently – at Xopus of course – and I wondered about the call stack size. Here is the test, and the results:

Safari surprises me, it’s just 10% of Firefox! Opera stands out quite clearly as well.

link | javascript | 16 August 2007, 08:42


Comments

  1. Safari 3.0.3: 100

    Robbert Broersma | 16 August 2007, 09:34 | link

  2. Swift 0.2: 1000. That’s weird, Swift and Safari use both Webkit, Swift is just a Windows port (or am I wrong on that?).

    IE6 gives an error for overflow, but then displays 893.

    But, is 100 not just enough? I don’t see the need for so much subroutines in things I’ve worked on.

    Arjan Eising | 16 August 2007, 10:03 | link

  3. Gran Paradiso also has 1001.

    Arjan, I think a 100 is too low. I’d reckon it’s quickly reached in complex systems (like Xopus).

    Mark Wubben | 16 August 2007, 10:48 | link

  4. This is WebKit bug 4045. There’s some concern of crashing the browser by overflowing the native call stack, but they’re working on it.

    I posted a somewhat simpler stack depth experiment in my Chiron project SVN a while back.

    Kris Kowal | 16 August 2007, 19:01 | link

  5. Hey Kris, thanks for the update. Your experiment looks into recursion, which should give the same results but with a different error message.

    Mark Wubben | 16 August 2007, 20:46 | link

  6. The latest Safari3 beta also reports 100… :(

    Håvard Pedersen | 20 August 2007, 11:01 | link

  7. FYI Opera’s and IE’s call stack sizes are limited by the size of your ram which is why e.g. Arjan saw a limit of ~800. Firefox’ is fixed in the engine (but I don’t know if it’s a configuration or a compilation limit) and Safari’s is fixed at the compilation.

    But, is 100 not just enough? I don’t see the need for so much subroutines in things I’ve worked on.

    When you use a somewhat functional style, or a CPS style, in JS… a call stack limit of 100 is pretty much trivial to blow.

    Masklinn | 20 August 2007, 13:21 | link

  8. I recently just wrote this about getting around the call stack in Flash which has a limit of 256 levels. I’m not 100% sure this would be helpful, but I know Actionscript and JavaScript are pretty much the same.

    nLokers | 20 August 2007, 13:30 | link

  9. Hi, a few points:

    Firefox 1-2 and older Mozilla variants have had 1000 hardwired as the maximum call count (so the fencepost is 1001 — an off by one bug, but who’s counting? ;-). This limit was meant to defeat trivial denial-of-service attacks and save developers who make a runaway recursive function call by mistake from a browser crash.

    But for several years we’ve used stack address sampling to enforce a 512K limit on stack depth from near top level event loop to deepest JS flow that samples in various opportunistic places in recursive or common functions. So we do not need the 1001 limit and I’ll file a bug to remove it (filed — thanks for prompting this).

    For JS2/ES4 we are requiring proper tail calls. So CPS code will work without overflow.

    HTH,

    /be

    Brendan Eich | 21 August 2007, 02:31 | link

  10. Hey Brendan, thanks for the clarification. I think there was a brief discussion regarding call stacks at Kris Zyp’s talk at the Ajax Experience last month, don’t quite recall what number you mentioned back then. Anyway, sweet to see you’re removing the limit!

    Mark Wubben | 21 August 2007, 07:55 | link

  11. The bug on the 1001 limit has been fixed for Firefox 3.

    /be

    Brendan Eich | 22 August 2007, 19:28 | link

  12. @ Mark As you can read in my comment, I have not that much experience with large applications. What is the minimum Xopus needs by the way?

    @ Brendan Good to see that bugs like this are that quickly reported and solved after only reading a blog post :)

    Arjan Eising | 24 August 2007, 08:43 | link

  13. Arjan, for the best experience you’ll need a fast machine, lots of memory and IE 7. Say an ‘06 or ‘07 machine with plenty of memory.

    Mark Wubben | 24 August 2007, 08:58 | link

  14. I was going to test the Safari Beta for Windows for you but it crashed every time I tried to load this page…

    Not that that should surprise anyone. Taking Safari to Windows is likely a headache that we web developers could have done without.

    Go the Fox..

    Yani

    Yani | 27 August 2007, 18:37 | link

  15. @Arjan Eising- We ran into the stack size issue with the Safari browser. All we are doing is taking a 2-dimensional array (5 columns, 401 rows) and separating each column into it’s own one-dimensional array. From there, we quick-sort, then unique the one-dimensional array. Safari comes back with a “Maximum call stack size exceeded” error in the JavaScript console. So clearly, it’s fairly easy to fill a 100 stack array.

    Aaron | 28 August 2007, 00:29 | link

  16. Safari 3.0.4 on Leopard reports 500.

    Nicholas Shanks | 24 November 2007, 01:15 | link

  17. Hi there! New browser Firefox 3 Beta 1 reports: Maximum call stack size: 261503.
    Pretty much. Is it true value?

    EvGen | 30 November 2007, 12:32 | link

  18. Safari 3.0.5 (525.3) - pre 3.0.6 (connect.apple.com): 500

    Kanman | 27 December 2007, 20:16 | link

  19. err, what do you do when you cant send email cause it says

    “Maximum call stack size exceeded”

    any clues? im using safari.

    benj

    benj | 14 March 2008, 07:09 | link

  20. Safari Webkit Build 34318 give back 161317!

    SP | 3 June 2008, 12:55 | link

  21. On Leopard:

    • Webkit (build 34271 and 34318): 149796
    • Safari 3.1.1 (5525.20): 500
    • Firefox 3.0 : 3001

    Egill | 3 June 2008, 16:53 | link

  22. Glad to see Opera is not only the faster, but also the one with bigger JS call stack!

    Guti | 7 June 2008, 12:15 | link

  23. Opera 9.50 , Linux, maximum call stack 9999

    Witek | 21 June 2008, 17:45 | link

  24. IE7 gives an error for overflow, maximum call stack size exceeded.

    Gareth | 26 June 2008, 06:41 | link

Leave your comment

Please keep it polite and on topic. Yes, your e-mail address is required, but it's kept private. HTML is not allowed in the comments but you can use Markdown. Non-contributing comments run the risk of being removed. Especially if the website seem “fishy”. Spammers, beware.

(required)
(required, kept private)
(optional, but let's share it!)
(required)

Remember my details


Novemberborn: Extra

About the author

Mark Wubben is a hacker/writer in Enschede, the Netherlands.

Read more about Mark...

Go to

Jobs (NL)

Xopus zoekt programmeurs! Verbeter de code en win!

Subscribe