views:

131

answers:

1

This is my first game with JSON and I am surprised how slow it is.

I am quite sure I am missing something and I'll be gratefull if someone can help.

Here is my code

$.getJSON('/localhost/CountryList', function (data)
{
   alert ("finished");
});

My countryList returns an array like this

{"Code":"AF","Name":"Afghanistan"},
{"Code":"AX","Name":"Aland Islands"},
{"Code":"AL","Name":"Albania"},

etc....

The full size of my array is about 6K and It takes more than 1m 30s to have it rendered by the browser from my local development IIS.

When I used the compression, the size goes to 2K but the time is still 1m 20s

Is it normal that JSON is so slow?

A: 

Can you look at your interaction in Firebug or Chrome's developer tool dialog to see where the time is being spent? How is the AJAX content being generated? Is it a static resource on the server, or is there some dynamic work with some potentially lengthy database magic that needs to take place? Is it waiting for the AJAX result, or is it really in the rendering?

Also, if you host the data locally (and temporarily, for this exercise) in your page itself, is the rendering reasonably fast?

Chris Farmer
When I put the content in a text file, I can open it instantaneously from the browser
nachid
Are you saying that you can pull the content into the browser via getJSON "instantaneously" when the content exists as a static file? Or are you saying that you can simply open the text file with the browser? If the former, then it looks like there's no problem with jQuery or your use of getJSON. The bottleneck then is in your server-side code to generate the content.
Chris Farmer
no, what I meant is opening the text file with the browser.In my code, I ma generating the data from my database and I can see with my debugger that the time is spent between the moment where it is sent to the webserver and the time when it is rendered to the browser
nachid
But several things happen during that time... the content must be generated on the server, the content must be acquired by the browser, and the html content must be rendered based on that data. It's not clear (to me, anyway) where that delay really is. What have you done to isolate the bottleneck to one of those areas?
Chris Farmer
I am wondering if there is any tool that can help isolating this bottleneck
nachid
Firebug could help see the duration of the network requests, but also just including your json data inline in your page, or hosting it as a static external resource while still accessing it via getJSON.
Chris Farmer
I created a brand new project and I could not reproduce the caseThere is something wrong with my project that I am investigating
nachid