From f916ec26a672a0212275ba5d39abd021c582c8f8 Mon Sep 17 00:00:00 2001 From: Martin Kralik Date: Tue, 27 Oct 2015 05:07:45 -0700 Subject: [PATCH] removed unnecessary dispatches to main queue Summary: There is no point in dispatching to main thread if there is nothing to do there. This place gets called basically any time a repeating js timer fires, which doesn't imply UI changes (although usually that's why people setup timers). Combined with previous diffs that makes us not generate empty blocks (nil instead), this could be minor perf win in some rare cases. This also changes semantic of `reactBridgeDidFinishTransaction` call a bit. Previously it was done no matter if UI has changed or not. I think it should be safe, since seems like callees really care only about views being laid out. Depends on D2571166. (not strictly speaking) public Reviewed By: jspahrsummers, nicklockwood Differential Revision: D2571188 fb-gh-sync-id: 02d52e4615475072c3c27226e67c431a667ec990 --- React/Modules/RCTUIManager.m | 40 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index bfc77eae7b..fe35779e2d 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -898,31 +898,31 @@ RCT_EXPORT_METHOD(findSubviewIn:(nonnull NSNumber *)reactTag atPoint:(CGPoint)po _pendingUIBlocks = [NSMutableArray new]; [_pendingUIBlocksLock unlock]; - // Execute the previously queued UI blocks - RCTProfileBeginFlowEvent(); - dispatch_async(dispatch_get_main_queue(), ^{ - RCTProfileEndFlowEvent(); - RCTProfileBeginEvent(0, @"UIManager flushUIBlocks", nil); - @try { - for (dispatch_block_t block in previousPendingUIBlocks) { - block(); - } - /** - * TODO(tadeu): Remove it once and for all - */ - if (previousPendingUIBlocks.count) { + if (previousPendingUIBlocks.count) { + // Execute the previously queued UI blocks + RCTProfileBeginFlowEvent(); + dispatch_async(dispatch_get_main_queue(), ^{ + RCTProfileEndFlowEvent(); + RCTProfileBeginEvent(0, @"UIManager flushUIBlocks", nil); + @try { + for (dispatch_block_t block in previousPendingUIBlocks) { + block(); + } + /** + * TODO(tadeu): Remove it once and for all + */ for (id node in _bridgeTransactionListeners) { [node reactBridgeDidFinishTransaction]; } } - } - @catch (NSException *exception) { - RCTLogError(@"Exception thrown while executing UI block: %@", exception); - } - RCTProfileEndEvent(0, @"objc_call", @{ - @"count": @(previousPendingUIBlocks.count), + @catch (NSException *exception) { + RCTLogError(@"Exception thrown while executing UI block: %@", exception); + } + RCTProfileEndEvent(0, @"objc_call", @{ + @"count": @(previousPendingUIBlocks.count), + }); }); - }); + } } RCT_EXPORT_METHOD(measure:(nonnull NSNumber *)reactTag