mirror of
https://github.com/status-im/react-native.git
synced 2025-01-16 04:24:15 +00:00
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:
parent
f2a60a202f
commit
915e5826ef
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user