[thelist] Re: javascript optimization question

Matt Warden mwarden at gmail.com
Wed May 4 10:13:11 CDT 2005


On 5/4/05, Sam Foster <sam at sam-i-am.com> wrote:
> 
> >>I have a question on javascript scripting engine:
> >>
> >>Does javascript scripting engine do any optimization to function call,
> >>as in java?

Volkan,

I originally wanted to reply to your question and say that I'm almost
certain that Javascript does not, but I could not get google to spit
up anything supporting this.

Basically, my logic is that what you want cannot be done in Javascript
unless the interpreter makes multiple passes over the code during
execution. My thoughts were that it is unlikely that JS does this, but
as it turns out I am only partially correct (finally got google to
spit something up today):

Sayeth Mozilla:
"JavaScript 2.0 follows the streaming execution model -- the entire
program is processed in one pass. Unlike in JavaScript 1.x,
declarations take effect only when they are executed. A declaration
that is never executed is ignored.

The streaming execution model considerably simplifies the language and
allows a JavaScript 2.0 interpreter to treat programs read from a file
identically to programs typed in via an interactive console. Also, a
JavaScript 2.0 interpreter or just-in-time compiler may start to
execute a script even before it has finished downloading all of it.
This was not possible in JavaScript 1.x because the interpreter was
required to scan the entire program for declarations in one pass
before executing any of the code in the following pass."
http://www.mozilla.org/js/language/js20-1999-03-25/execution-model.html

However, my interpretation of the document above is that the multiple
passes are only for variable typing and NOT for optimization. But,
since there are multiple passes, a Javascript engine could conceivably
make use of them for optimization purposes.

That said, I doubt that the level of optimizations you are concerned
with are achieved by any Javascript engine. Unfortunately, this is
only speculation.


-- 
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.


More information about the thelist mailing list