Ticket filed: http://dev.jquery.com/ticket/4680
Fix landed: http://dev.jquery.com/changeset/6361 --John On Wed, May 20, 2009 at 10:24 AM, John Resig <[email protected]> wrote: > Ok, it all sounds in order to me - someone want to file a ticket? > http://dev.jquery.com/newticket > > --John > > > > On Wed, May 20, 2009 at 10:04 AM, mike.helgeson > <[email protected]>wrote: > >> >> The YUI compressor does not seem complain about using the Function >> technique. >> >> (function(){ >> >> function evaluate( data ){ >> return Function("return "+( data ) )(); >> }; >> >> })(); >> >> becomes... >> >> (function(){function A(B){return Function("return "+(B))()}})(); >> >> >> On May 20, 9:06 am, John Resig <[email protected]> wrote: >> > Has anyone been able to figure out if YUIMin still behaves as you would >> > expect it to? >> > >> > --John >> > >> > On Wed, May 20, 2009 at 6:48 AM, Andrea Giammarchi < >> > >> > [email protected]> wrote: >> > > Ok, the reason eval is so slow is because of FireBug, it costed 17 >> seconds >> > > with FireBug enabled while FireBug seems to do not affect Function >> execution >> > > (which makes Function against better than eval). >> > >> > > In any case, Function is faster or exactly fast as eval is, even in >> > > Internet Explorer, at least in my tests. >> > >> > > this is a truly simple readapted test case: >> > >> > > <!DOCTYPE html> >> > > <script type="text/javascript"> >> > > portable = (function(msg, i, interval){ >> > > function timeout(){ >> > > alert(msg.join("\n")); >> > > msg = []; >> > > i = 0; >> > > }; >> > > return { >> > > log:function(test){ >> > > msg[i++] = test; >> > > clearTimeout(interval); >> > > interval = setTimeout(timeout, 100); >> > > } >> > > } >> > > })([], 0, 0); >> > > var count = 10000, o = null, i = 0, jsonString = >> > > >> '{"value":{"items":[{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3},{"x":1,"y":2,"z":3}]},"error":null}'; >> > > var beginTime = new Date(); >> > > for ( i = 0; i < count; i++ ) >> > > o = eval( "(" + jsonString + ")" ); >> > > portable.log( "eval:" + ( new Date() - beginTime ) ); >> > > var beginTime = new Date(); >> > > for ( i = 0; i < count; i++ ) >> > > o = new Function( "return " + jsonString )(); >> > > portable.log( "new Function:" + ( new Date() - beginTime ) ); >> > > var beginTime = new Date(); >> > > for ( i = 0; i < count; i++ ) >> > > o = Function( "return " + jsonString )(); >> > > portable.log( "Function:" + ( new Date() - beginTime ) ); >> > > var beginTime = new Date(); >> > > var callback = Function( "return " + jsonString ); >> > > for ( i = 0; i < count; i++ ) >> > > o = callback(); >> > > portable.log( "precompiled Function:" + ( new Date() - beginTime ) ); >> > > if(this.JSON){ >> > > var beginTime = new Date(); >> > > for ( i = 0; i < count; i++ ) >> > > o = JSON.parse(jsonString); >> > > portable.log( "native:" + ( new Date() - beginTime ) ); >> > > }; >> > > </script> >> > >> > > Let me know what you think. >> > >> > > Regards >> > >> > > On Wed, May 20, 2009 at 7:43 AM, Andrea Giammarchi < >> > > [email protected]> wrote: >> > >> > >> As I said, Function does not do scope resolution except the global >> one so >> > >> in my opinion should be always preferred for JSON evaluations. >> Firefox does >> > >> not care about implicit returned value plus brackets plus scope, it >> simply >> > >> create the anonimous function doing a syntax check and returns errors >> only >> > >> at call time so if there are no errors the precompiled funcion will >> be like >> > >> a manual one, time for parsing syntax is then one against every eval >> call. >> > >> To be fair, that bench make sense declaring the function once and >> simply >> > >> calling it inside the for to always return the same object. >> Unfortunately >> > >> this is not a real world case. >> > >> > >> On May 20, 2009 7:33 AM, "Michael Geary" <[email protected]> wrote: >> > >> > >> Function( 'return ' + data )() is also MUCH faster in Firefox than >> eval. >> > >> > >> In a test case of JSON data containing 1000 names and addresses >> (about >> > >> 112KB), eval() takes a full second to execute on my machine in >> Firefox 3. On >> > >> all other browsers (including IE!) it takes hardly any time at all. >> > >> > >> The Function version takes essentially no time in Firefox. (Didn't >> test it >> > >> in other browsers.) >> > >> > >> -Mike >> > >> > >> ------------------------------ >> > >> *From:* [email protected] [mailto: >> [email protected]] >> > >> *On Behalf Of *John Resig >> > >> *Sent:* Tuesday, May 19, 2009 4:20 PM >> > >> *To:* [email protected] >> > >> *Subject:* [jquery-dev] Re: window['eval']() in rhino >> > >> > >> > I don't remember the original discussion/change, off-hand. If >> YUIMin is >> > >> still able to generate an ... >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---
