From ebe614b8c90083f70fe93a8121a6806c2b7afa9d Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Wed, 7 Jan 2015 15:27:34 -0800 Subject: [PATCH] Dispatch lazy image downloaders to another thread fixes #148 --- AsyncDisplayKit/ASNetworkImageNode.mm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/AsyncDisplayKit/ASNetworkImageNode.mm b/AsyncDisplayKit/ASNetworkImageNode.mm index 8e7f5e2e3c..c1c2a51400 100644 --- a/AsyncDisplayKit/ASNetworkImageNode.mm +++ b/AsyncDisplayKit/ASNetworkImageNode.mm @@ -234,11 +234,17 @@ } }; - [_cache fetchCachedImageWithURL:_URL - callbackQueue:dispatch_get_main_queue() - completion:cacheCompletion]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + [_cache fetchCachedImageWithURL:_URL + callbackQueue:dispatch_get_main_queue() + completion:cacheCompletion]; + }); } else { - [self _downloadImageWithCompletion:finished]; + // NSURLSessionDownloadTask will do file I/O to create a temp directory. If called on the main thread this + // will cause significant performance issues. + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + [self _downloadImageWithCompletion:finished]; + }); } } }