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

Re: Iterating through a huge JSON variable - freezes FF

Expand Messages
  • 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 1 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 2 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 3 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.