Loading ...
Sorry, an error occurred while loading the content.

Re: [json] Iterating through a huge JSON variable - freezes FF

Expand Messages
  • mertsakarya@hotmail.com
    Once we ve had long running script on the client-side, which took about 1 minutes to execute/parse/display the data(a two dimensional array with thousands of
    Message 1 of 10 , Feb 7, 2007
    • 0 Attachment
      Once we've had long running script on the client-side, which took about 1 minutes to execute/parse/display the data(a two dimensional array with thousands of rows).
      First of all, this shouldn't happen, but if you can't avoid it, do it asychronously.

      What we did was, we created an "interval", and parsed them by the hundreds (less or more for your situation) each time.
      This increased responsiveness of the page.

      The idea is; use asynchronousity while downloading the data and if the data is huge, use asynchronousity again to parse/display the data.

      Mert


      ----- Original Message -----
      From: carl.harroch
      To: json@yahoogroups.com
      Sent: Wednesday, February 07, 2007 2:07 PM
      Subject: [json] Iterating through a huge JSON variable - freezes FF


      Hello,

      I am trying to iterate through a big JSON variable (about 1500 nodes).
      It works but FF pops up with the message saying the script is not
      responding (A script on this page may be busy... do you want to stop
      the script, debug, continue). If I select continue, it works fine. It
      is just that the iteration takes a bit of time to go through all the
      nodes. Is there a way to avoid the above? I searched a bit the net and
      it is not very clear how to do so as JS is not multithreaded from what
      I could gather. However, I am sure, there could be some asynchron
      iteration releasing the cpu from time to time to ensure nothing else
      needs to be done on the page.

      Any ideas?

      /Carl





      [Non-text portions of this message have been removed]
    • mertsakarya@hotmail.com
      One more thought, Why not use [ [ , ],... (array) notation instead of [{attributes: {name: , id: }}], ? Mert ... From:
      Message 2 of 10 , Feb 7, 2007
      • 0 Attachment
        One more thought,
        Why not use [ [<name, string>, <id, string>],...
        (array) notation instead of [{attributes: {name: "", id: ""}}], ?

        Mert
        ----- Original Message -----
        From: carl.harroch
        To: json@yahoogroups.com
        Sent: Wednesday, February 07, 2007 2:07 PM
        Subject: [json] Iterating through a huge JSON variable - freezes FF


        Hello,

        I am trying to iterate through a big JSON variable (about 1500 nodes).
        It works but FF pops up with the message saying the script is not
        responding (A script on this page may be busy... do you want to stop
        the script, debug, continue). If I select continue, it works fine. It
        is just that the iteration takes a bit of time to go through all the
        nodes. Is there a way to avoid the above? I searched a bit the net and
        it is not very clear how to do so as JS is not multithreaded from what
        I could gather. However, I am sure, there could be some asynchron
        iteration releasing the cpu from time to time to ensure nothing else
        needs to be done on the page.

        Any ideas?

        /Carl





        [Non-text portions of this message have been removed]
      • carl.harroch
        ... It was generated with the JSON addin to RoR. Will look into that later on. I try to avoid the trip back to the server and download the list just once.
        Message 3 of 10 , Feb 8, 2007
        • 0 Attachment
          > Nitpick: this isn't valid JSON, get those hash keys quoted.
          It was generated with the JSON addin to RoR. Will look into that later on.

          I try to avoid the trip back to the server and download the list just
          once. Could it be better to do the following:

          1. Download the entire JSON
          2. Iterate through the first 100 and break
          3. back to step 2 until the entire JSON has been iterated


          --- In json@yahoogroups.com, Michal Migurski <mike-jsonphp@...> wrote:
          >
          > > And my data.json:
          > >
          > > ---
          > > [{attributes: {name: "ca", id: "2"}}, {attributes: {name:
          > > "111ffrrferf", id: "3"}},.... * 2000 records
          >
          > Nitpick: this isn't valid JSON, get those hash keys quoted.
          >
          >
          > > I am pretty sure I know where the error comes from. It is due to the
          > > this.resultContainer.innerHTML... I tried briefly to save it to a temp
          > > before exchanging the innerHTML and I could see a real change in the
          > > time it takes to load the json.
          > >
          > > Do you beleive my code is a good approach on generating html from
          > > large JSON?
          > >
          > > I still beleive it is not a clean solution. I am very new to
          > > Javascript. Multi-threading will be needed in the features especially
          > > with the usage of AJAX and controller logic being more and more on the
          > > client side. How does the AJAX request approach the subject?
          >
          > Iterating over 2000 of anything in Javascript is going to cause
          > problems for most browsers - visit a heavily-commented page on Digg
          > for another example of greedy, blocking loops in a production site. =)
          >
          > Try to break this problem down into smaller chunks, as Matthew
          > suggested. For example, divide the 2000-element request into 100-
          > element requests, and chain them together so that a new request is
          > fired only after the previous response has been received and handled.
          > It will take longer overall and require more trips to and from the
          > server, but giving the browser some breathing room to address user
          > input or UI tasks will make it feel snappier. This kind of
          > asynchronous (the "A" in "Ajax"), chunked-out approach gets you most
          > of the benefits of multithreading without the headaches.
          >
          > -mike.
          >
          > ----------------------------------------------------------------
          > michal migurski- contact info and pgp key:
          > sf/ca http://mike.teczno.com/contact.html
          >
        • Michal Migurski
          ... Yuck, file a bug report. There s no excuse for generating javascript and calling it JSON. ... Maybe, though it depends on how long it takes to parse the
          Message 4 of 10 , Feb 8, 2007
          • 0 Attachment
            > > Nitpick: this isn't valid JSON, get those hash keys quoted.
            > It was generated with the JSON addin to RoR. Will look into that
            > later on.

            Yuck, file a bug report. There's no excuse for generating javascript
            and calling it JSON.


            > I try to avoid the trip back to the server and download the list just
            > once. Could it be better to do the following:
            >
            > 1. Download the entire JSON
            > 2. Iterate through the first 100 and break
            > 3. back to step 2 until the entire JSON has been iterated

            Maybe, though it depends on how long it takes to parse the entire
            message - there's an upper limit of reasonability to this, too. You
            don't want to download a 10,000 item array and parse that in one go,
            or discover the array that presents no problems on your browser but
            brings an older or slower computer to its knees.

            I wrote a quick blog post specifically about chunking this kind of
            task out, with some tiny example code:
            http://mike.teczno.com/notes/polite-loops.html

            -mike.

            ----------------------------------------------------------------
            michal migurski- contact info and pgp key:
            sf/ca http://mike.teczno.com/contact.html
          • carl.harroch
            Thanks Mike, I beleive I will go for your last solution. Currently I am working on several part of my site which does not permit a lot of time on the iterating
            Message 5 of 10 , Feb 15, 2007
            • 0 Attachment
              Thanks Mike,

              I beleive I will go for your last solution. Currently I am working on
              several part of my site which does not permit a lot of time on the
              iterating part. As soon as I manage to test some different setup on
              different, I will post back a summary of my founding.

              I keep you updated,
              Carl

              --- In json@yahoogroups.com, Michal Migurski <mike-jsonphp@...> wrote:
              >
              > > > Nitpick: this isn't valid JSON, get those hash keys quoted.
              > > It was generated with the JSON addin to RoR. Will look into that
              > > later on.
              >
              > Yuck, file a bug report. There's no excuse for generating javascript
              > and calling it JSON.
              >
              >
              > > I try to avoid the trip back to the server and download the list just
              > > once. Could it be better to do the following:
              > >
              > > 1. Download the entire JSON
              > > 2. Iterate through the first 100 and break
              > > 3. back to step 2 until the entire JSON has been iterated
              >
              > Maybe, though it depends on how long it takes to parse the entire
              > message - there's an upper limit of reasonability to this, too. You
              > don't want to download a 10,000 item array and parse that in one go,
              > or discover the array that presents no problems on your browser but
              > brings an older or slower computer to its knees.
              >
              > I wrote a quick blog post specifically about chunking this kind of
              > task out, with some tiny example code:
              > http://mike.teczno.com/notes/polite-loops.html
              >
              > -mike.
              >
              > ----------------------------------------------------------------
              > michal migurski- contact info and pgp key:
              > sf/ca http://mike.teczno.com/contact.html
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.