Account Options

  1. Sign in
Google Groups Home
« Groups Home
SpiderMonkey: Increasing JSContext stack size slows down my scripts
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
rush@manbert.com  
View profile  
 More options Mar 5 2007, 1:47 pm
Newsgroups: mozilla.dev.tech.js-engine
From: "r...@manbert.com" <r...@manbert.com>
Date: 5 Mar 2007 10:47:00 -0800
Subject: SpiderMonkey: Increasing JSContext stack size slows down my scripts
I am using Spider Monkey to add scripting capability to my app. I have
had it running for quite a while with no problems. I have a single
JSRuntime and a single JSContext. 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.

All of the time can be accounted for in the execution of the
JavaScript code. I call the JS code from C++, and it calls into my C+
+,
but I have satisfied myself that the delays are not in the C++
code. The script code I'm running is marshaling and unmarshaling
objects to JSON. It appears that doing an eval on the JSON encoded
data is taking 3-4 seconds when I have a 1 Meg stack. That accounts
for a lot of the extra time right there.

Has anyone else seen anything like this? I searched the list archives
and didn't see anything that looked similar.

Here is a related question: Does anyone have any stack size
guidelines? I have read js_InternalInvoke and it sets up the stack
frame size as ((argc + 2) * 4) bytes, and I also see that js_Invoke
allocates space for local variables and missing arguments on the
stack. I might be fine with a 100K stack, but my customers will be
writing the scripts, so I don't really have any control over what they
do.

Any help would be greatly appreciated.

- Rush


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
rush@manbert.com  
View profile  
 More options Mar 7 2007, 5:20 pm
Newsgroups: mozilla.dev.tech.js-engine
From: "r...@manbert.com" <r...@manbert.com>
Date: 7 Mar 2007 14:20:18 -0800
Local: Wed, Mar 7 2007 5:20 pm
Subject: Re: SpiderMonkey: Increasing JSContext stack size slows down my scripts
I made a mistake when I reported this. I got an offer of help as a
reply off list. While creating the example, I realized that eval() was
not what was taking longer. It was the JSON serialization code, which
was still in a logging function call. I still don't know why stack
size changes the timing (it is a factor of about 30 slower for a 100
times larger stack), but eval() is not a problem.

- Rush


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Orendorff  
View profile  
 More options Mar 8 2007, 1:32 am
Newsgroups: mozilla.dev.tech.js-engine
From: "Jason Orendorff" <jason.orendo...@gmail.com>
Date: 7 Mar 2007 22:32:53 -0800
Local: Thurs, Mar 8 2007 1:32 am
Subject: Re: SpiderMonkey: Increasing JSContext stack size slows down my scripts
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Moening  
View profile  
 More options Mar 8 2007, 5:22 pm
Newsgroups: mozilla.dev.tech.js-engine
From: "Mike Moening" <Mi...@RetekSolutions.com>
Date: Thu, 8 Mar 2007 16:22:35 -0600
Local: Thurs, Mar 8 2007 5:22 pm
Subject: Re: SpiderMonkey: Increasing JSContext stack size slows down my scripts
Jason,
Can you update the wiki and fix it?

Here is the link:  http://developer.mozilla.org/en/docs/JS_NewContext

That one got me too.
8K versus 8Megs makes a BIG difference!

"Jason Orendorff" <jason.orendo...@gmail.com> wrote in message

news:1173335573.424409.256400@p10g2000cwp.googlegroups.com...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »