Tieme
Tieme

Reputation: 65389

dispatch_async slower then performSelectorInBackground:?

In my application I used the performSelectorInBackground: to load images from disk. After some unit testing with dispatch_async i decided to replace my performSelectorInBackground with dispatch_async calls.

dispatch_queue_t currentBackgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_async(currentBackgroundQueue, ^{
    [self getImageFromDisk:sPath delegate:(id)delegate];
});

The code seems to work, but now my images load slower then before. This causes a black image when the user scrolls through the images.

My application contains some kind of photoscroller. I cannot use apple's tiling sample code because it increases the app size to much. I use this snippet to load the image from disk.

Upvotes: 2

Views: 1548

Answers (1)

deleted_user
deleted_user

Reputation: 3805

Ive said this on other similar questions before, using dispatch async on the global queue will cause synchronous like behavior especially for code that eventually updates the UI. YMMV but when I have tried it its more or less the same result as a synchronous call. Create and use your own queue, or (create and use your own queue) with NSOperations.

I believe the reason for this is that any events posted to the global queue will consume the queues processing time even though the code is technically asynch. Dont use the global queue for background ops.

Use a custom queue and pump your own runloop.

Upvotes: 5

Related Questions