Increase Performance of Metro Apps by 46% with 2 Lines of Code

JSON is “faster” than XML

Using JSON data in lieu of XML will make your Metro apps 46% faster!

It’s true.

Rendered JSON data is smaller than XML. Which means JSON requires less time to travel.

Even better, Windows 8 offers full support for JSON! Metro UI controls can be bound to JSON data. Also, common JavaScript functions, such as JSON.parse(), are natively supported. JSON is a first class citizen in Windows 8.

“But, I don’t have JSON data. I have XML data.”

Don’t worry – I’ll get to that.

The Facts

Using Fiddler, we will measure the resulting file size and network transfer time of an RSS feed in XML and JSON format. For our sample data, we’ll use the wildly famous, unbelievably spectacular and world renowned Internet show,  “The Metro Developer Show” </shameless plug>

Below, a screenshot from Fiddler depicting the network transfer times of our RSS feed in XML and JSON format. 62 seconds vs. 33 seconds!

XML – 62 seconds
xml_time
JSON – 33 seconds
json_time

Of course, the above screen shots uses a theoretical network speed of 6KB/sec. This would never rarely happen. But it could. And why not code for the lowest common dominator!?

Let’s take a look at file sizes. Below, we see the resulting file sizes of the RSS feed in XML and JSON format. What a difference!

XML – 376,744 bytes
xml_bytes
JSON – 201,529 bytes
json_bytes

Less data. Less time. Everyone wins!

How To Parse XML as JSON with 2 Lines of Code

Many of us avoid using JSON data because, simply put, we don’t have access to our data in JSON format. You will now! The below code snippet shows an XHR JavaScript request made by a Windows 8 Metro App coded in HTML5/JavaScript. The secret? We use Google’s API for AJAX as a conduit. We send Google our RSS feed URL and Google sends it back as JSON!!!

All we need is 2 lines of code. One line specifies the URL of our XML feed. The second line encodes our URL and concatenates it with the base URL for the Google API. Then we make our normal XHR request. Instant JSON data endpoint! Free, fast and highly available!

https://gist.github.com/2315098

Tweet about this on Twitter15Share on Facebook1Share on Google+3Share on LinkedIn2Pin on Pinterest0

Comments

  1. Joakim Dahl says:

    Are the data sizes the compressed size? Just to make you example match reality a bit more.

  2. Joakim Dahl says:

    Are the data sizes the compressed size? Just to make you example match reality a bit more.

  3. ryanlowdermilk says:

    Joakim,

    Yes, I believe the values show above are compressed. Let me know if I’m incorrect.

  4. ryanlowdermilk says:

    Joakim,

    Yes, I believe the values show above are compressed. Let me know if I’m incorrect.

Speak Your Mind

*