2 Replies Latest reply on Nov 10, 2009 6:20 AM by Bertrand G.

    Concurrent image (batch) loading

    Bertrand G. Level 1

      First, is it really possible? I have been struggling for days creating a batchLoader for images, but it seems to be missing something...

       

      Here is what I did (AIR app):

      1. scan a directory to load all images

      2. create and load an URLLoader with file.url reference (URLRequest)

      3. onLoadingComplete, create and loadBytes on the urlLoader

      4. onParsingComplete, create the image

      [repeat steps 2-4 by batch of 100s until no more file in directory]

      5. display the images

       

      This sounds fine... or at least I hoped

       

      PROBLEM:

      Only a portion of the files make it to the full loading process... meaning that some events on the second loader are not triggered.

       

      Facts:

      - out of 651 images in the directory, some 470 images are actually loaded.

      - Less images are loaded if I am in debug mode

      - sequential loading (one after the other) works fine

      - This loading method as proven me to be the best so far to recover the memory on images deletion

      - A counter in the onLoadingComplete (URLLoader) shows the correct count 651, while a counter in the onParsingComplete (simple Loader) gives around 470.. WHERE ARE THE LOST EVENTS?

       

      it seems like we are losing events when there are too many... Does anyone have advice/comment/thoughts on this?

        • 1. Re: Concurrent image (batch) loading
          paul.williams Level 4

          I/O operations are asynchronous, but that doesn't mean they run in parallel with each other. I doubt that the Air runtime will be loading your files simultaneously using hundreds of threads, so your requests are probably being queued-up under the hood. Even if it did spawn multiple threads, it is unlikely you will see significant gains over loading files sequentially.

           

           

           

           

           

          I cannot explain the missing events, so these may be due to problems with the queuing mechanism. You could try listening for other events from your loader / parser objects in case any fault conditions are being reported. For example, LoaderInfo dispatches "ioError" and "Progress" events.

           

           

           

           

           

          However, since your approach is unlikely to have any advantages over sequential loading you'd probably be better off just keeping it simple. Sequential loading has a number of advantages: It is much easier to show progress to the user, it is easy to halt the loading process and it is more efficient.

          1 person found this helpful
          • 2. Re: Concurrent image (batch) loading
            Bertrand G. Level 1

            Thank you very much for your answer.

             

            Actually I can see significant speed change using batch loading (batch of 5, 10, 20...) especially for small images; the ratio can be several times faster (when it is not missing file).  If the batch size is to big, I start missing quite a bit.

             

            But it is an interesting remark that I might be limited by the I/O access... I haven't thought about that.

            I tried listening to events like IOError, or SecurityError, but none of them seemed to be triggered.

             

            Anyhow, I still find it quite odd that events get discarded like that! And I can't find any documentation or thread about this anywhere.

             

            I will investigate a little more before turning to sequential loading.