From 82c8129627aa857040a4a39aef49cf03869e6ed3 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 22 Jul 2016 09:50:48 -0700 Subject: [PATCH] Fix double React perflogger creation Reviewed By: mmmulani Differential Revision: D3599003 fbshipit-source-id: 25090309c92127b403d1df6a8b7c18ad5a088b5e --- React/Base/RCTBatchedBridge.m | 5 +++++ React/Base/RCTBridge+Private.h | 11 +++-------- React/Base/RCTBridge.m | 11 +++++++---- React/Base/RCTPerformanceLogger.h | 2 +- React/Base/RCTRootView.m | 8 ++++---- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index e9e1f608d..e3d9ea0d3 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -57,6 +57,7 @@ RCT_EXTERN NSArray *RCTGetModuleClasses(void); @synthesize flowIDMapLock = _flowIDMapLock; @synthesize loading = _loading; @synthesize valid = _valid; +@synthesize performanceLogger = _performanceLogger; - (instancetype)initWithParentBridge:(RCTBridge *)bridge { @@ -68,6 +69,10 @@ RCT_EXTERN NSArray *RCTGetModuleClasses(void); launchOptions:bridge.launchOptions]) { _parentBridge = bridge; + _performanceLogger = [RCTPerformanceLogger new]; + [_performanceLogger markStartForTag:RCTPLBridgeStartup]; + [_performanceLogger markStartForTag:RCTPLTTI]; + /** * Set Initial State */ diff --git a/React/Base/RCTBridge+Private.h b/React/Base/RCTBridge+Private.h index e7693685b..f69e2beec 100644 --- a/React/Base/RCTBridge+Private.h +++ b/React/Base/RCTBridge+Private.h @@ -10,14 +10,9 @@ #import "RCTBridge.h" @class RCTModuleData; -@class RCTPerformanceLogger; @protocol RCTJavaScriptExecutor; @interface RCTBridge () -{ -@public - RCTPerformanceLogger *_performanceLogger; -} // Private designated initializer - (instancetype)initWithDelegate:(id)delegate @@ -134,9 +129,9 @@ @interface RCTBatchedBridge : RCTBridge -@property (nonatomic, weak) RCTBridge *parentBridge; -@property (nonatomic, weak) id javaScriptExecutor; -@property (nonatomic, assign) BOOL moduleSetupComplete; +@property (nonatomic, weak, readonly) RCTBridge *parentBridge; +@property (nonatomic, weak, readonly) id javaScriptExecutor; +@property (nonatomic, assign, readonly) BOOL moduleSetupComplete; - (instancetype)initWithParentBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER; diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 030ca3825..f515a8731 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -132,15 +132,13 @@ static RCTBridge *RCTCurrentBridgeInstance = nil; launchOptions:(NSDictionary *)launchOptions { if (self = [super init]) { - _performanceLogger = [RCTPerformanceLogger new]; - [_performanceLogger markStartForTag:RCTPLBridgeStartup]; - [_performanceLogger markStartForTag:RCTPLTTI]; - _delegate = delegate; _bundleURL = bundleURL; _moduleProvider = block; _launchOptions = [launchOptions copy]; + [self setUp]; + RCTExecuteOnMainQueue(^{ [self bindKeys]; }); } return self; @@ -182,6 +180,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) #endif } +- (RCTPerformanceLogger *)performanceLogger +{ + return self.batchedBridge.performanceLogger; +} + - (NSArray *)moduleClasses { return self.batchedBridge.moduleClasses; diff --git a/React/Base/RCTPerformanceLogger.h b/React/Base/RCTPerformanceLogger.h index 9477a0ec6..ab37e1d54 100644 --- a/React/Base/RCTPerformanceLogger.h +++ b/React/Base/RCTPerformanceLogger.h @@ -85,7 +85,7 @@ typedef NS_ENUM(NSUInteger, RCTPLTag) { - (NSArray *)valuesForTags; /** - * Returns a duration (stop_time - start_time) for given RCTPLTag. + * Returns a duration in ms (stop_time - start_time) for given RCTPLTag. */ - (int64_t)durationForTag:(RCTPLTag)tag; diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 20fc643a1..fe0b3ed2d 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -14,7 +14,7 @@ #import #import "RCTAssert.h" -#import "RCTBridge+Private.h" +#import "RCTBridge.h" #import "RCTEventDispatcher.h" #import "RCTKeyCommands.h" #import "RCTLog.h" @@ -92,7 +92,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat object:self]; if (!_bridge.loading) { - [self bundleFinishedLoading:_bridge.batchedBridge]; + [self bundleFinishedLoading:_bridge]; } [self showLoadingView]; @@ -259,7 +259,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) _appProperties = [appProperties copy]; if (_contentView && _bridge.valid && !_bridge.loading) { - [self runApplication:_bridge.batchedBridge]; + [self runApplication:_bridge]; } } @@ -340,7 +340,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder) - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex { [super insertReactSubview:subview atIndex:atIndex]; - [_bridge->_performanceLogger markStopForTag:RCTPLTTI]; + [_bridge.performanceLogger markStopForTag:RCTPLTTI]; dispatch_async(dispatch_get_main_queue(), ^{ if (!self->_contentHasAppeared) { self->_contentHasAppeared = YES;