Skip to content

Commit 200245e

Browse files
christophpurrermeta-codesync[bot]
authored andcommitted
Drop RCTBridge from RCTPerfMonitor (#59258)
Summary: Pull Request resolved: #59258 Route JS-thread dispatch through the injected dispatchToJSThread block and read the injected performanceLogger. Delete the Views counter, which can only show zero since RCTViewRegistry exposes no enumeration, and reflow the HUD bar. Changelog: [iOS][Removed] - Remove the non-functional Views counter from the PerfMonitor HUD Reviewed By: shwanton Differential Revision: D126567926 fbshipit-source-id: dddd4bd9d9e4b1842ed1f865e818b3ca8c9beaf8
1 parent c1efbba commit 200245e

1 file changed

Lines changed: 23 additions & 43 deletions

File tree

‎packages/react-native/React/CoreModules/RCTPerfMonitor.mm‎

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
#import <React/RCTDevSettings.h>
1919

20-
#import <React/RCTBridge+Private.h>
21-
#import <React/RCTBridge.h>
20+
#import <React/RCTBridgeModule.h>
21+
#import <React/RCTEventDispatcherProtocol.h>
2222
#import <React/RCTFPSGraph.h>
2323
#import <React/RCTInitializing.h>
2424
#import <React/RCTInvalidating.h>
@@ -58,8 +58,13 @@ static vm_size_t RCTGetResidentMemorySize(void)
5858
return memoryUsageInByte;
5959
}
6060

61-
@interface RCTPerfMonitor
62-
: NSObject <RCTBridgeModule, RCTTurboModule, RCTInvalidating, UITableViewDataSource, UITableViewDelegate>
61+
@interface RCTPerfMonitor : NSObject <
62+
RCTBridgeModule,
63+
RCTTurboModule,
64+
RCTInvalidating,
65+
RCTJSDispatcherModule,
66+
UITableViewDataSource,
67+
UITableViewDelegate>
6368

6469
#if __has_include(<React/RCTDevMenu.h>)
6570
@property (nonatomic, strong, readonly) RCTDevMenuItem *devMenuItem;
@@ -68,7 +73,6 @@ @interface RCTPerfMonitor
6873
@property (nonatomic, strong, readonly) UIView *container;
6974
@property (nonatomic, strong, readonly) UILabel *memory;
7075
@property (nonatomic, strong, readonly) UILabel *heap;
71-
@property (nonatomic, strong, readonly) UILabel *views;
7276
@property (nonatomic, strong, readonly) UITableView *metrics;
7377
@property (nonatomic, strong, readonly) RCTFPSGraph *jsGraph;
7478
@property (nonatomic, strong, readonly) RCTFPSGraph *uiGraph;
@@ -85,7 +89,6 @@ @implementation RCTPerfMonitor {
8589
UIView *_container;
8690
UILabel *_memory;
8791
UILabel *_heap;
88-
UILabel *_views;
8992
UILabel *_uiGraphLabel;
9093
UILabel *_jsGraphLabel;
9194
UITableView *_metrics;
@@ -109,8 +112,9 @@ @implementation RCTPerfMonitor {
109112
NSArray *_perfLoggerMarks;
110113
}
111114

112-
@synthesize bridge = _bridge;
115+
@synthesize dispatchToJSThread = _dispatchToJSThread;
113116
@synthesize moduleRegistry = _moduleRegistry;
117+
@synthesize performanceLogger = _performanceLogger;
114118

115119
RCT_EXPORT_MODULE()
116120

@@ -172,7 +176,7 @@ - (UIView *)container
172176
UIEdgeInsets safeInsets = RCTKeyWindow().safeAreaInsets;
173177

174178
_container =
175-
[[UIView alloc] initWithFrame:CGRectMake(safeInsets.left, safeInsets.top, 180, RCTPerfMonitorBarHeight)];
179+
[[UIView alloc] initWithFrame:CGRectMake(safeInsets.left, safeInsets.top, 136, RCTPerfMonitorBarHeight)];
176180
_container.layer.borderWidth = 2;
177181
_container.layer.borderColor = [UIColor lightGrayColor].CGColor;
178182
[_container addGestureRecognizer:self.gestureRecognizer];
@@ -212,38 +216,26 @@ - (UILabel *)heap
212216
return _heap;
213217
}
214218

215-
- (UILabel *)views
216-
{
217-
if (_views == nullptr) {
218-
_views = [[UILabel alloc] initWithFrame:CGRectMake(88, 0, 44, RCTPerfMonitorBarHeight)];
219-
_views.font = [UIFont systemFontOfSize:12];
220-
_views.numberOfLines = 3;
221-
_views.textAlignment = NSTextAlignmentCenter;
222-
}
223-
224-
return _views;
225-
}
226-
227219
- (RCTFPSGraph *)uiGraph
228220
{
229221
if (_uiGraph == nullptr) {
230-
_uiGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(134, 14, 40, 30) color:[UIColor lightGrayColor]];
222+
_uiGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(90, 14, 40, 30) color:[UIColor lightGrayColor]];
231223
}
232224
return _uiGraph;
233225
}
234226

235227
- (RCTFPSGraph *)jsGraph
236228
{
237229
if (_jsGraph == nullptr) {
238-
_jsGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(178, 14, 40, 30) color:[UIColor lightGrayColor]];
230+
_jsGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(134, 14, 40, 30) color:[UIColor lightGrayColor]];
239231
}
240232
return _jsGraph;
241233
}
242234

243235
- (UILabel *)uiGraphLabel
244236
{
245237
if (_uiGraphLabel == nullptr) {
246-
_uiGraphLabel = [[UILabel alloc] initWithFrame:CGRectMake(134, 3, 40, 10)];
238+
_uiGraphLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 3, 40, 10)];
247239
_uiGraphLabel.font = [UIFont systemFontOfSize:11];
248240
_uiGraphLabel.textAlignment = NSTextAlignmentCenter;
249241
_uiGraphLabel.text = @"UI";
@@ -255,7 +247,7 @@ - (UILabel *)uiGraphLabel
255247
- (UILabel *)jsGraphLabel
256248
{
257249
if (_jsGraphLabel == nullptr) {
258-
_jsGraphLabel = [[UILabel alloc] initWithFrame:CGRectMake(178, 3, 38, 10)];
250+
_jsGraphLabel = [[UILabel alloc] initWithFrame:CGRectMake(134, 3, 38, 10)];
259251
_jsGraphLabel.font = [UIFont systemFontOfSize:11];
260252
_jsGraphLabel.textAlignment = NSTextAlignmentCenter;
261253
_jsGraphLabel.text = @"JS";
@@ -289,7 +281,6 @@ - (void)show
289281

290282
[self.container addSubview:self.memory];
291283
[self.container addSubview:self.heap];
292-
[self.container addSubview:self.views];
293284
[self.container addSubview:self.uiGraph];
294285
[self.container addSubview:self.uiGraphLabel];
295286

@@ -309,12 +300,12 @@ - (void)show
309300
[self.container addSubview:self.jsGraph];
310301
[self.container addSubview:self.jsGraphLabel];
311302

312-
[_bridge
313-
dispatchBlock:^{
314-
self->_jsDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(threadUpdate:)];
315-
[self->_jsDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
316-
}
317-
queue:RCTJSThread];
303+
if (_dispatchToJSThread != nullptr) {
304+
_dispatchToJSThread(^{
305+
self->_jsDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(threadUpdate:)];
306+
[self->_jsDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
307+
});
308+
}
318309
}
319310

320311
- (void)hide
@@ -415,15 +406,6 @@ - (void)parse:(NSString *)log
415406

416407
- (void)updateStats
417408
{
418-
NSDictionary<NSNumber *, UIView *> *views = [_bridge.uiManager valueForKey:@"viewRegistry"];
419-
NSUInteger viewCount = views.count;
420-
NSUInteger visibleViewCount = 0;
421-
for (UIView *view in views.allValues) {
422-
if ((view.window != nullptr) || (view.superview.window != nullptr)) {
423-
visibleViewCount++;
424-
}
425-
}
426-
427409
// Ensure the container always stays on top of newly added views
428410
if ([_container.superview.subviews lastObject] != _container) {
429411
[_container.superview bringSubviewToFront:_container];
@@ -432,8 +414,6 @@ - (void)updateStats
432414
double mem = (double)RCTGetResidentMemorySize() / 1024 / 1024;
433415
self.memory.text = [NSString stringWithFormat:@"RAM\n%.2lf\nMB", mem];
434416
self.heap.text = [NSString stringWithFormat:@"JSC\n%.2lf\nMB", (double)_heapSize / 1024];
435-
self.views.text =
436-
[NSString stringWithFormat:@"Views\n%lu\n%lu", (unsigned long)visibleViewCount, (unsigned long)viewCount];
437417

438418
__weak __typeof__(self) weakSelf = self;
439419
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@@ -481,7 +461,7 @@ - (void)loadPerformanceLoggerData
481461
{
482462
NSUInteger i = 0;
483463
NSMutableArray<NSString *> *data = [NSMutableArray new];
484-
RCTPerformanceLogger *performanceLogger = [_bridge performanceLogger];
464+
RCTPerformanceLogger *performanceLogger = _performanceLogger;
485465
NSArray<NSNumber *> *values = [performanceLogger valuesForTags];
486466
for (NSString *label in LabelsForRCTPerformanceLoggerTags()) {
487467
long long value = values[i + 1].longLongValue - values[i].longLongValue;

0 commit comments

Comments
 (0)