Subj : Re: Looking for Spidermonkey equivalent of Mozilla/DOM trick... To : Anton van Straaten From : Brendan Eich Date : Wed Nov 26 2003 03:36 pm Anton van Straaten wrote: > I have a Javascript program implemented partly in continuation-passing > style (it was converted from Scheme). Because of the CPS, the program > can recurse very deeply - deep enough to fill the Javascript stack > before getting much useful work done. > > Happily, it turns out that in this particular program at least, it's > possible to reduce the stack depth requirement, by every now and then > "resetting" the process by passing a closure to the DOM > window.setTimeout method and allowing the current procedure to > terminate. With this trick, the program works very well, particularly > under Mozilla - it can reach levels that would have required recursing > a million levels deep. (IE is not nearly that good.) > > Since this program is already structured around setTimeout, I'm > wondering if there are any easy tricks similar to setTimeout that I > can use under Spidermonkey without DOM? I could implement a > trampoline-style top-level loop and do this myself, I'm just looking > for a lazy way out. > > (BTW, I'm aware of the CPS version of Rhino with tail-call > optimization. I'm guessing nothing like that currently exists for > Spidermonkey...) SpiderMonkey itself knows nothing about event loops, and knows little about threads, although it can be used from multiple threads (JS_THREADSAFE). So without tail-recursion elimination, you're not going to get any kind of "automagic" solution from the core engine. So, into what kind of event loop or thread architecture are you embedding SpiderMonkey "without DOM"? If DOM is gone, what's left? Is the program based on Mozilla? /be .