diff --git a/React/Base/RCTPerformanceLogger.h b/React/Base/RCTPerformanceLogger.h index 87e8831c8..051254fcc 100644 --- a/React/Base/RCTPerformanceLogger.h +++ b/React/Base/RCTPerformanceLogger.h @@ -16,6 +16,7 @@ typedef NS_ENUM(NSUInteger, RCTPLTag) { RCTPLScriptExecution, RCTPLRAMBundleLoad, RCTPLRAMStartupCodeSize, + RCTPLRAMNativeRequires, RCTPLRAMNativeRequiresCount, RCTPLRAMNativeRequiresSize, RCTPLNativeModuleInit, diff --git a/React/Base/RCTPerformanceLogger.m b/React/Base/RCTPerformanceLogger.m index d1a37f1e6..b30d1348d 100644 --- a/React/Base/RCTPerformanceLogger.m +++ b/React/Base/RCTPerformanceLogger.m @@ -89,6 +89,7 @@ NSArray *RCTPerformanceLoggerLabels(void) @"ScriptExecution", @"RAMBundleLoad", @"RAMStartupCodeSize", + @"RAMNativeRequires", @"RAMNativeRequiresCount", @"RAMNativeRequiresSize", @"NativeModuleInit", diff --git a/React/Executors/RCTJSCExecutor.m b/React/Executors/RCTJSCExecutor.m index fce63819e..940222c1b 100644 --- a/React/Executors/RCTJSCExecutor.m +++ b/React/Executors/RCTJSCExecutor.m @@ -678,8 +678,10 @@ static int readBundle(FILE *fd, size_t offset, size_t length, void *ptr) { - (void)registerNativeRequire { + RCTPerformanceLoggerSet(RCTPLRAMNativeRequires, 0); RCTPerformanceLoggerSet(RCTPLRAMNativeRequiresCount, 0); RCTPerformanceLoggerSet(RCTPLRAMNativeRequiresSize, 0); + __weak RCTJSCExecutor *weakSelf = self; [self addSynchronousHookWithName:@"nativeRequire" usingBlock:^(NSString *moduleName) { RCTJSCExecutor *strongSelf = weakSelf; @@ -687,8 +689,13 @@ static int readBundle(FILE *fd, size_t offset, size_t length, void *ptr) { return; } + RCTPerformanceLoggerAdd(RCTPLRAMNativeRequiresCount, 1); + RCTPerformanceLoggerAppendStart(RCTPLRAMNativeRequires); RCT_PROFILE_BEGIN_EVENT(0, [@"nativeRequire_" stringByAppendingString:moduleName], nil); + ModuleData *data = (ModuleData *)CFDictionaryGetValue(strongSelf->_jsModules, moduleName.UTF8String); + RCTPerformanceLoggerAdd(RCTPLRAMNativeRequiresSize, data->length); + char bytes[data->length]; if (readBundle(strongSelf->_bundle, data->offset, data->length, bytes) != 0) { RCTFatal(RCTErrorWithMessage(@"Error loading RAM module")); @@ -700,10 +707,9 @@ static int readBundle(FILE *fd, size_t offset, size_t length, void *ptr) { CFDictionaryRemoveValue(strongSelf->_jsModules, moduleName.UTF8String); JSStringRelease(code); - RCT_PROFILE_END_EVENT(0, @"js_call", nil); - RCTPerformanceLoggerAdd(RCTPLRAMNativeRequiresCount, 1); - RCTPerformanceLoggerAdd(RCTPLRAMNativeRequiresSize, data->length); + RCT_PROFILE_END_EVENT(0, @"js_call", nil); + RCTPerformanceLoggerAppendEnd(RCTPLRAMNativeRequires); if (!result) { dispatch_async(dispatch_get_main_queue(), ^{