That one got me too.
8K versus 8Megs makes a BIG difference!
...
> On Mar 5, 1:47 pm, Rush <r
...@manbert.com> wrote:
> > [...] Since I started, I have given my
> > JSContext a 100K byte stack. Today I changed that to 1 Meg and the
> > script that I was testing with slowed down by a factor of 25 to 30
> > (from about one-quarter of a second to over 6 seconds). When I
> > increased the stack size to 10 Meg, the script slowed down by another
> > factor of about 6.
> Hi Rush,
> Short answer: Use 8192 and don't worry. :)
> Long answer: The parameter to JS_NewContext() is not the stack size.
> The documentation in the wiki is wrong. The parameter is actually the
> chunk size of the stack pool--an obscure memory management tuning
> knob.
> Which knob *should* you be tweaking, then? Probably none.
> SpiderMonkey's stack behavior is not what you might expect. When a
> JavaScript function calls another JavaScript function, it doesn't use
> any C stack at all: JavaScript stack frames are allocated from the
> stack pool (heap memory).
> The limit for recursion depth among JavaScript functions is 1000 calls
> (MAX_INTERP_LEVEL, defined in jsinterp.c). This is way high. Every
> time I've ever hit this limit, it was a bug in my JavaScript code.
> By the way-- the slowness you're seeing only happens in debug builds.
> In a debug build, each time arena memory is freed, SpiderMonkey does a
> memset() across the entire unused portion of the arena chunk. (See
> JS_CLEAR_UNUSED, defined in jsarena.h). This makes memory look tidy
> in a debugger, but when the chunk size is very large, it's slow. In
> release builds ("make BUILD_OPT=1 -f Makefile.ref"), the memset()
> doesn't happen.
> Cheers,
> Jason Orendorff