Skip to content

#7587 - $.parseJSON huge performance optimization by skipping regex#98

Merged
0 commit merged intojquery:masterfrom
fracmak:master
Mar 7, 2011
Merged

#7587 - $.parseJSON huge performance optimization by skipping regex#98
0 commit merged intojquery:masterfrom
fracmak:master

Conversation

@fracmak
Copy link

@fracmak fracmak commented Nov 16, 2010

this checking skips the expensive regex/replace validation on the JSON when using the browser's native JSON parser because the threat to security is gone. My tests show this reduces the runtime of the parseJSON function to 1/3rd of the original code.

#7587

@paulirish
Copy link
Member

jay, can you do a jsperf test on this

@fracmak
Copy link
Author

fracmak commented Nov 16, 2010

@jaubourg
Copy link
Member

The test was still there because Chrome's JSON parser was too lenient, IIRC.

Have they fixed it?

@staabm
Copy link
Contributor

staabm commented Nov 17, 2010

in Opera 9.64 this breaks.

@fracmak
Copy link
Author

fracmak commented Nov 17, 2010

Is there a unit test or example of the issue in chrome?

@fracmak
Copy link
Author

fracmak commented Nov 17, 2010

I've updated the jsperf test to fix an issue with scope on older browsers that had trouble with the way I patched in the new parseJSON function. (the patch remains the same, I merely declared the variables that could be conflicted). Could you try Opera again?

@fracmak
Copy link
Author

fracmak commented Nov 17, 2010

Sorry, new url is http://jsperf.com/parsejson-optimization/2

@staabm
Copy link
Contributor

staabm commented Nov 17, 2010

the fixed version works in Opera 9.64

@csnover
Copy link
Member

csnover commented Nov 21, 2010

I’ve created a ticket on Trac for this issue, #7587. FWIW, my own real-world applications have this optimization in place already because JSON parsing of long strings was taking upwards of 15 seconds; without the regexp, it takes less than 1 second.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments