Restricted image decoding to 2 simultaneous threads

Reviewed By: zjj010104

Differential Revision: D2922292

fb-gh-sync-id: eddd47d02fc721acc1da69e7483c6570997320b5
shipit-source-id: eddd47d02fc721acc1da69e7483c6570997320b5
This commit is contained in:
Nick Lockwood 2016-02-10 12:48:41 -08:00 committed by facebook-github-bot-7
parent f2a60a202f
commit 915e5826ef
1 changed files with 9 additions and 2 deletions

View File

@ -38,6 +38,7 @@
{
NSArray<id<RCTImageURLLoader>> *_loaders;
NSArray<id<RCTImageDataDecoder>> *_decoders;
NSOperationQueue *_imageDecodeQueue;
dispatch_queue_t _URLCacheQueue;
NSURLCache *_URLCache;
}
@ -474,7 +475,13 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image,
completionHandler:completionHandler];
} else {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Serialize decoding to prevent excessive memory usage
if (!_imageDecodeQueue) {
_imageDecodeQueue = [NSOperationQueue new];
_imageDecodeQueue.name = @"com.facebook.react.ImageDecoderQueue";
_imageDecodeQueue.maxConcurrentOperationCount = 2;
}
[_imageDecodeQueue addOperationWithBlock:^{
if (cancelled) {
return;
}
@ -501,7 +508,7 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image,
NSError *finalError = RCTErrorWithMessage(errorMessage);
completionHandler(finalError, nil);
}
});
}];
return ^{
OSAtomicOr32Barrier(1, &cancelled);