3

When an ALAssetsGroup is large, there is a delay of several seconds between the time enumerateAssetsUsingBlock: or enumerateAssetsAtIndexes: is called and the time the first enumeration block is called.

On an iPad 2 with 10000 assets in the library, this delay is approximately 4.2 seconds before the first asset block is called.

Photos.app on the same device with the same library starts in less than a second showing all photos in the library. I have no idea how it does this. That's the kind of behaviour we would like to see.

This is a minimal test case that shows the behaviour:

ALAssetsLibrary* assetLibrary = [ALAssetsLibrary new];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupLibrary
                            usingBlock:^(ALAssetsGroup *group, BOOL *stop)
 {
     if (group != nil) {
         NSLog(@"*** Got library group, start timer");
         NSDate* tic = [NSDate date];

         [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop)
          {
              if (result==nil) {
                  NSLog(@"*** Elapsed time to final enumeration: %.2fs", -[tic timeIntervalSinceNow]);
              }
              else if (index==0) {
                  NSLog(@"*** Elapsed time to image 0: %.2fs", -[tic timeIntervalSinceNow]);
              }
          }];

         *stop = YES;
     }
 }
                          failureBlock:^(NSError *error)
 {
     NSLog(@"ERROR: %@", [error localizedDescription]);
 }];

Output:

*** Got library group, start timer
*** Elapsed time to image 0: 4.20s
*** Elapsed time to final enumeration: 4.20s

(Note that the solution accepted in this (slightly different) question does not work. The delay happens before the first asset is even reached: Possible ways to speed up reading from ALAssetsLibrary and populating a UITableView )

Community
  • 1
  • 1
Eric Brochu
  • 188
  • 1
  • 8
  • please check my answer here http://stackoverflow.com/questions/13508535/add-uiimageview-into-uiscrollview-inside-block-with-alasset/13508841#13508841 – Shamsudheen TK Feb 11 '13 at 02:42
  • Thanks, @ramshad, it's a good thought, but I've already tried it and no, it doesn't appear to be a thread-blocking issue. Putting the method call into dispatch_sync(dispatch_get_main_queue(), {...}) doesn't change it. And in any case, there's no reason for the main thread to be blocked for 4+ seconds. – Eric Brochu Feb 12 '13 at 17:08
  • please check this two links:- http://stackoverflow.com/questions/13508535/alasset-photo-library-image-performance-improvements-when-its-loading-slow/13508841#13508841 – Shamsudheen TK Dec 05 '14 at 05:36
  • http://stackoverflow.com/questions/10239242/possible-ways-to-speed-up-reading-from-alassetslibrary-and-populating-a-uitablev – Shamsudheen TK Dec 05 '14 at 05:36

0 Answers0