Skip to content

Commit 60e60a9

Browse files
p-sunfacebook-github-bot
authored andcommitted
Refactor: Assign string label to each case in RCTPLTag enum for startup performance logging
Summary: `_labelsForTags` is an array with string labels used only for local profiling, that we had to manually keep it in sync with `RCTPLTag`. Refactor so labels are assigned with switch instead. Changelog: [iOS] Refactor: Assign string label to each case in RCTPLTag enum for startup performance logging Reviewed By: fkgozali Differential Revision: D32889043 fbshipit-source-id: 81da592a160a31b91e78289be0990cc2ff960f29
1 parent d393e94 commit 60e60a9

9 files changed

+121
-75
lines changed

BUCK

+2
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ REACT_PUBLIC_HEADERS = {
287287
"React/RCTModuleMethod.h": RCTBASE_PATH + "RCTModuleMethod.h",
288288
"React/RCTMultipartStreamReader.h": RCTBASE_PATH + "RCTMultipartStreamReader.h",
289289
"React/RCTNullability.h": RCTBASE_PATH + "RCTNullability.h",
290+
"React/RCTPLTag.h": RCTBASE_PATH + "RCTPLTag.h",
290291
"React/RCTPackagerClient.h": RCTDEVSUPPORT_PATH + "RCTPackagerClient.h",
291292
"React/RCTPackagerConnection.h": RCTDEVSUPPORT_PATH + "RCTPackagerConnection.h",
292293
"React/RCTPerformanceLogger.h": RCTBASE_PATH + "RCTPerformanceLogger.h",
294+
"React/RCTPerformanceLoggerLabels.h": RCTBASE_PATH + "RCTPerformanceLoggerLabels.h",
293295
"React/RCTPointerEvents.h": RCTVIEWS_PATH + "RCTPointerEvents.h",
294296
"React/RCTProfile.h": "React/Profiler/RCTProfile.h",
295297
"React/RCTPushNotificationManager.h": RCTLIB_PATH + "PushNotificationIOS/RCTPushNotificationManager.h",

React/Base/RCTPLTag.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
typedef NS_ENUM(NSInteger, RCTPLTag) {
9+
RCTPLScriptDownload = 0,
10+
RCTPLScriptExecution,
11+
RCTPLRAMBundleLoad,
12+
RCTPLRAMStartupCodeSize,
13+
RCTPLRAMStartupNativeRequires,
14+
RCTPLRAMStartupNativeRequiresCount,
15+
RCTPLRAMNativeRequires,
16+
RCTPLRAMNativeRequiresCount,
17+
RCTPLNativeModuleInit,
18+
RCTPLNativeModuleMainThread,
19+
RCTPLNativeModulePrepareConfig,
20+
RCTPLNativeModuleMainThreadUsesCount,
21+
RCTPLNativeModuleSetup,
22+
RCTPLTurboModuleSetup,
23+
RCTPLJSCWrapperOpenLibrary,
24+
RCTPLBridgeStartup,
25+
RCTPLTTI,
26+
RCTPLBundleSize,
27+
RCTPLReactInstanceInit,
28+
RCTPLSize // This is used to count the size
29+
};

React/Base/RCTPerformanceLogger.h

+1-30
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,7 @@
66
*/
77

88
#import <Foundation/Foundation.h>
9-
10-
// Keep this in sync with _labelsForTags
11-
typedef NS_ENUM(NSInteger, RCTPLTag) {
12-
RCTPLScriptDownload = 0,
13-
RCTPLScriptExecution,
14-
RCTPLRAMBundleLoad,
15-
RCTPLRAMStartupCodeSize,
16-
RCTPLRAMStartupNativeRequires,
17-
RCTPLRAMStartupNativeRequiresCount,
18-
RCTPLRAMNativeRequires,
19-
RCTPLRAMNativeRequiresCount,
20-
RCTPLNativeModuleInit,
21-
RCTPLNativeModuleMainThread,
22-
RCTPLNativeModulePrepareConfig,
23-
RCTPLNativeModuleMainThreadUsesCount,
24-
RCTPLNativeModuleSetup,
25-
RCTPLTurboModuleSetup,
26-
RCTPLJSCWrapperOpenLibrary,
27-
RCTPLBridgeStartup,
28-
RCTPLTTI,
29-
RCTPLBundleSize,
30-
RCTPLReactInstanceInit,
31-
RCTPLSize // This is used to count the size
32-
};
9+
#import "RCTPLTag.h"
3310

3411
@interface RCTPerformanceLogger : NSObject
3512

@@ -95,10 +72,4 @@ typedef NS_ENUM(NSInteger, RCTPLTag) {
9572
*/
9673
- (int64_t)valueForTag:(RCTPLTag)tag;
9774

98-
/**
99-
* Returns an array with values for all tags.
100-
* Use RCTPLTag to go over the array.
101-
*/
102-
- (NSArray<NSString *> *)labelsForTags;
103-
10475
@end

React/Base/RCTPerformanceLogger.m

+4-34
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,24 @@
99

1010
#import "RCTLog.h"
1111
#import "RCTPerformanceLogger.h"
12+
#import "RCTPerformanceLoggerLabels.h"
1213
#import "RCTProfile.h"
1314
#import "RCTRootView.h"
1415

1516
@interface RCTPerformanceLogger () {
1617
int64_t _data[RCTPLSize][2];
17-
NSUInteger _cookies[RCTPLSize];
18+
NSInteger _cookies[RCTPLSize];
1819
}
1920

20-
@property (nonatomic, copy) NSArray<NSString *> *labelsForTags;
21-
2221
@end
2322

2423
@implementation RCTPerformanceLogger
2524

26-
- (instancetype)init
27-
{
28-
if (self = [super init]) {
29-
// Keep this in sync with RCTPLTag
30-
_labelsForTags = @[
31-
@"ScriptDownload",
32-
@"ScriptExecution",
33-
@"RAMBundleLoad",
34-
@"RAMStartupCodeSize",
35-
@"RAMStartupNativeRequires",
36-
@"RAMStartupNativeRequiresCount",
37-
@"RAMNativeRequires",
38-
@"RAMNativeRequiresCount",
39-
@"NativeModuleInit",
40-
@"NativeModuleMainThread",
41-
@"NativeModulePrepareConfig",
42-
@"NativeModuleMainThreadUsesCount",
43-
@"NativeModuleSetup",
44-
@"TurboModuleSetup",
45-
@"JSCWrapperOpenLibrary",
46-
@"BridgeStartup",
47-
@"RootViewTTI",
48-
@"BundleSize",
49-
@"ReactInstanceInit",
50-
];
51-
}
52-
return self;
53-
}
54-
5525
- (void)markStartForTag:(RCTPLTag)tag
5626
{
5727
#if RCT_PROFILE
5828
if (RCTProfileIsProfiling()) {
59-
NSString *label = _labelsForTags[tag];
29+
NSString *label = RCTPLLabelForTag(tag);
6030
_cookies[tag] = RCTProfileBeginAsyncEvent(RCTProfileTagAlways, label, nil);
6131
}
6232
#endif
@@ -68,7 +38,7 @@ - (void)markStopForTag:(RCTPLTag)tag
6838
{
6939
#if RCT_PROFILE
7040
if (RCTProfileIsProfiling()) {
71-
NSString *label = _labelsForTags[tag];
41+
NSString *label = RCTPLLabelForTag(tag);
7242
RCTProfileEndAsyncEvent(RCTProfileTagAlways, @"native", _cookies[tag], label, @"RCTPerformanceLogger");
7343
}
7444
#endif
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <React/RCTDefines.h>
9+
#import "RCTPLTag.h"
10+
11+
// Return the string label for the enum RCTPLTag for performance logging
12+
__attribute__((used)) RCT_EXTERN NSString *RCTPLLabelForTag(RCTPLTag tag);
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "RCTPerformanceLoggerLabels.h"
9+
#import <React/RCTAssert.h>
10+
11+
NSString *RCTPLLabelForTag(RCTPLTag tag)
12+
{
13+
switch (tag) {
14+
case RCTPLScriptDownload:
15+
return @"ScriptDownload";
16+
case RCTPLScriptExecution:
17+
return @"ScriptExecution";
18+
case RCTPLRAMBundleLoad:
19+
return @"RAMBundleLoad";
20+
case RCTPLRAMStartupCodeSize:
21+
return @"RAMStartupCodeSize";
22+
case RCTPLRAMStartupNativeRequires:
23+
return @"RAMStartupNativeRequires";
24+
case RCTPLRAMStartupNativeRequiresCount:
25+
return @"RAMStartupNativeRequiresCount";
26+
case RCTPLRAMNativeRequires:
27+
return @"RAMNativeRequires";
28+
case RCTPLRAMNativeRequiresCount:
29+
return @"RAMNativeRequiresCount";
30+
case RCTPLNativeModuleInit:
31+
return @"NativeModuleInit";
32+
case RCTPLNativeModuleMainThread:
33+
return @"NativeModuleMainThread";
34+
case RCTPLNativeModulePrepareConfig:
35+
return @"NativeModulePrepareConfig";
36+
case RCTPLNativeModuleMainThreadUsesCount:
37+
return @"NativeModuleMainThreadUsesCount";
38+
case RCTPLNativeModuleSetup:
39+
return @"NativeModuleSetup";
40+
case RCTPLTurboModuleSetup:
41+
return @"TurboModuleSetup";
42+
case RCTPLJSCWrapperOpenLibrary:
43+
return @"JSCWrapperOpenLibrary";
44+
case RCTPLBridgeStartup:
45+
return @"BridgeStartup";
46+
case RCTPLTTI:
47+
return @"RootViewTTI";
48+
case RCTPLBundleSize:
49+
return @"BundleSize";
50+
case RCTPLReactInstanceInit:
51+
return @"ReactInstanceInit";
52+
case RCTPLSize: // Only used to count enum size
53+
RCTAssert(NO, @"RCTPLSize should not be used to track performance timestamps.");
54+
return nil;
55+
}
56+
}

React/CoreModules/RCTPerfMonitor.mm

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#import <React/RCTInvalidating.h>
2525
#import <React/RCTJavaScriptExecutor.h>
2626
#import <React/RCTPerformanceLogger.h>
27+
#import <React/RCTPerformanceLoggerLabels.h>
2728
#import <React/RCTRootView.h>
2829
#import <React/RCTUIManager.h>
2930
#import <React/RCTUtils.h>
@@ -40,6 +41,8 @@
4041

4142
typedef BOOL (*RCTJSCSetOptionType)(const char *);
4243

44+
NSArray<NSString *> *LabelsForRCTPerformanceLoggerTags();
45+
4346
static BOOL RCTJSCSetOption(const char *option)
4447
{
4548
static RCTJSCSetOptionType setOption;
@@ -515,7 +518,7 @@ - (void)loadPerformanceLoggerData
515518
NSMutableArray<NSString *> *data = [NSMutableArray new];
516519
RCTPerformanceLogger *performanceLogger = [_bridge performanceLogger];
517520
NSArray<NSNumber *> *values = [performanceLogger valuesForTags];
518-
for (NSString *label in [performanceLogger labelsForTags]) {
521+
for (NSString *label in LabelsForRCTPerformanceLoggerTags()) {
519522
long long value = values[i + 1].longLongValue - values[i].longLongValue;
520523
NSString *unit = @"ms";
521524
if ([label hasSuffix:@"Size"]) {
@@ -572,6 +575,15 @@ - (CGFloat)tableView:(__unused UITableView *)tableView heightForRowAtIndexPath:(
572575

573576
@end
574577

578+
NSArray<NSString *> *LabelsForRCTPerformanceLoggerTags()
579+
{
580+
NSMutableArray<NSString *> *labels = [NSMutableArray new];
581+
for (int i = 0; i < RCTPLSize; i++) {
582+
[labels addObject:RCTPLLabelForTag((RCTPLTag)i)];
583+
}
584+
return labels;
585+
}
586+
575587
#endif
576588

577589
Class RCTPerfMonitorCls(void)

packages/rn-tester/Podfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ SPEC CHECKSUMS:
891891
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
892892
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
893893
FBLazyVector: b81a2b70c72d8b0aefb652cea22c11e9ffd02949
894-
FBReactNativeSpec: 755b7fee1b08aefd74fb2fa9f7312b253719d536
894+
FBReactNativeSpec: 5bd61f19eb8d9ab489a9f89f6e862767fbb6cced
895895
Flipper: 30e8eeeed6abdc98edaf32af0cda2f198be4b733
896896
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
897897
Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c
@@ -904,7 +904,7 @@ SPEC CHECKSUMS:
904904
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
905905
glog: c10b67b343303f51715e5c5eedb18a41402f350a
906906
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
907-
MyNativeView: 4eaeecdc16568e81e702ef0a901127823d1ddc80
907+
MyNativeView: 68ba0ad4bcfc2bc9b776a346c70ca9d19a2f2542
908908
OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b
909909
RCT-Folly: 803a9cfd78114b2ec0f140cfa6fa2a6bafb2d685
910910
RCTRequired: af2d6080a4b9ba0885b28ca78879a92066c71cab
@@ -934,10 +934,10 @@ SPEC CHECKSUMS:
934934
React-RCTTest: 12bbd7fc2e72bd9920dc7286c5b8ef96639582b6
935935
React-RCTText: e9146b2c0550a83d1335bfe2553760070a2d75c7
936936
React-RCTVibration: 50be9c390f2da76045ef0dfdefa18b9cf9f35cfa
937-
React-rncore: d09af3a25cbff0b484776785676c28f3729e07f5
937+
React-rncore: 03e9b66d28812371afe3e7f180968f8e2a4ea71e
938938
React-runtimeexecutor: 4b0c6eb341c7d3ceb5e2385cb0fdb9bf701024f3
939939
ReactCommon: 7a2714d1128f965392b6f99a8b390e3aa38c9569
940-
ScreenshotManager: e8a3fc9b2e24b81127b36cb4ebe0eed65090c949
940+
ScreenshotManager: 6923f27c7ce9505117b8c743c9f099fa3054df6a
941941
Yoga: c0d06f5380d34e939f55420669a60fe08b79bd75
942942
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
943943

packages/rn-tester/RNTesterUnitTests/RCTPerformanceLoggerTests.m

-6
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,4 @@ @interface RCTPerformanceLoggerTests : XCTestCase
1515

1616
@implementation RCTPerformanceLoggerTests
1717

18-
- (void)testLabelCountInSyncWithRCTPLTag
19-
{
20-
RCTPerformanceLogger *logger = [RCTPerformanceLogger new];
21-
XCTAssertEqual([logger labelsForTags].count, RCTPLSize);
22-
}
23-
2418
@end

0 commit comments

Comments
 (0)