Skip to content

Commit

Permalink
Restricted image decoding to 2 simultaneous threads
Browse files Browse the repository at this point in the history
Reviewed By: zjj010104

Differential Revision: D2922292

fb-gh-sync-id: eddd47d02fc721acc1da69e7483c6570997320b5
shipit-source-id: eddd47d02fc721acc1da69e7483c6570997320b5
  • Loading branch information
nicklockwood authored and facebook-github-bot-7 committed Feb 10, 2016
1 parent f2a60a2 commit 915e582
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Libraries/Image/RCTImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ @implementation RCTImageLoader
{
NSArray<id<RCTImageURLLoader>> *_loaders;
NSArray<id<RCTImageDataDecoder>> *_decoders;
NSOperationQueue *_imageDecodeQueue;
dispatch_queue_t _URLCacheQueue;
NSURLCache *_URLCache;
}
Expand Down Expand Up @@ -474,7 +475,13 @@ - (RCTImageLoaderCancellationBlock)decodeImageDataWithoutClipping:(NSData *)data
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;
}
Expand All @@ -501,7 +508,7 @@ - (RCTImageLoaderCancellationBlock)decodeImageDataWithoutClipping:(NSData *)data
NSError *finalError = RCTErrorWithMessage(errorMessage);
completionHandler(finalError, nil);
}
});
}];

return ^{
OSAtomicOr32Barrier(1, &cancelled);
Expand Down

0 comments on commit 915e582

Please sign in to comment.