Opened 11 years ago
Closed 10 years ago
#7053 closed enhancement (wontfix)
Use new Function() instead of eval() for dojo.fromJson (and possibly other eval situations)
Reported by: | kriszyp | Owned by: | Kris Zyp |
---|---|---|---|
Priority: | high | Milestone: | future |
Component: | General | Version: | 1.1.1 |
Keywords: | JSON | Cc: | Adam Peller |
Blocked By: | Blocking: |
Description (last modified by )
Recently, I did some tests, and it appears that parsing JSON with: return new Function("return " + json)(); rather than: return eval("(" + json + ")"); is about twice as fast in FF (which has by far the slowest eval performance). It seems that it is also about 20% faster in IE (although IE is already way faster than FF with eval). See any problems with doing this?
Change History (10)
comment:1 Changed 11 years ago by
Description: | modified (diff) |
---|
comment:2 Changed 11 years ago by
comment:3 Changed 11 years ago by
You know I haven't tested this extensively yet, the ticket is definitely still at "research" stage right now :). I think new Function looked a little bit slower on Safari, however both eval and new Function are orders of magnitude faster in Safari than FF. I will test it with larger JSON blocks and get back to you.
comment:4 Changed 11 years ago by
Milestone: | 1.2 → 1.3 |
---|
comment:5 Changed 11 years ago by
As mentioned in bug #7290, could this be a result of the Firefox 3 regression bug mentioned in that ticket? If so, I am more inclined to punt this as a browser issue that should be fixed once they fix the regression.
comment:6 Changed 11 years ago by
This issue is almost entirely due to Firebug, not Firefox. I think there might be a slight regression in eval in FF, but it is very minor. One of the major features of Firebug 1.2 (FF3 version) is the ability to debug eval, which means all evals must be processed by Firebug and added to a list of scripts, which is understandably expensive.
comment:7 Changed 11 years ago by
Owner: | changed from kriszyp to Kris Zyp |
---|
comment:8 Changed 11 years ago by
Milestone: | 1.3 → 1.4 |
---|
comment:9 Changed 10 years ago by
My tests showed the opposite, that Function was 2x slower on FF, see #9664 (and also http://weblogs.asp.net/yuanjian/archive/2009/03/22/json-performance-comparison-of-eval-new-function-and-json.aspx, mentioned there).
comment:10 Changed 10 years ago by
Milestone: | 1.4 → future |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Sounds like this is a "wontfix", at least for now. Feel free to reopen if there's more evidence that Function() is faster in general.
Is this true for all sizes of JSON data? Just wondering if there is a size cutoff where the new Function() call introduces overhead that makes it slower than straight eval.
Also, how about Safari and Opera?