Subj : Re: Slow string conversion of long js functions To : netscape.public.mozilla.jseng From : Adrian Klein Date : Mon Jan 12 2004 08:16 pm Adrian Klein wrote: > Hi all, > > I occassionally found out that the conversion of javascript functions to > their String value in general seems to be very slow and not to scale to > well with the length of the function. I was just wondering if this could > be a useful hint for a future optimization and where it should be posted > if it should at all. > > A Testsite, that performs the conversion of a relative long js function > to its String value 10 times (took about 3500 ms on a PII 450 with Win98 > and Mozilla 1.5, whereas IE and Opera took only about 0 ms): > http://www.dragosan.net/slow_string.html > Well the answer I got why String(function) is so slow, is that the Spidermonkey Engine needs decompiles script bytecodes back to a String representing the function, whereas some other browsers seem to get keep the String representation in cache. What I had was a a skript used in a website that made use of a function that created a kind of a reference to another function. My first solution to do this was to get the name of the function and the named parameters out of the sourcecode of b() via some regular expressions. With a function consisting of 2000+ lines of code just the call String(function) took 3 seconds to decompile the function. I could get around this, by supplying the functions name to the function that created the references and using the apply function to call the referenced function with the arguments passed to a function meant to be referencing it. .