JSON, XML, performance

JSON is far better than XML! Less code to transfer – faster parsing – happy user. Right ? Hold that thought for a minute…

jQuery makes it pretty easy to manipulate XML; lured by which we began using jQuery in a big way in our product.  After some time we realized that the growing mound of JavaScript was causing significant performance penalties.  We began to see the “Unresponsive Script” message while the browser memory was steadily rising. Thanks to the firebug profiler we caught some of our goofs but were still not very happy on the performance front.  While attempting to parse and render large XML files (an average of 1000 to 2000 nodes nested 5 levels deep) we saw delays of 3-4 seconds. Firefox on mac was showing the spinner of death!

Alarmed we thought of removing nesting and moving the whole thing to JSON. No parsing – no creating JS objects means better performance and a happy user right ? Wrong!  It became a lot worse – 3 seconds became 15 and IE would just freeze. Some searching led us to John’s blog and to native JSON parsing. John gives a fair picture of how long it takes to parse JSON in comparison to XML.

JSON vs XML

And that is with just 1600 nodes of date records, think of 200 nested arrays and such! Solution and  strategies to this will hopefully be in another post.

PS: IE8 and Firefox 3.5  have native JSON support. But IE7 doesn’t and its going to take a while before our customers move to IE8.

Bookmark and Share