Skip to content

Commit f7df3bb

Browse files
nicklockwoodFacebook Github Bot 3
authored andcommitted
Removed eager init of all ViewManagers on layout
Summary:The `uiBlockToAmendWithShadowViewRegistry:` is called on every single view manager, on every single layout pass. This causes all view managers to be eagerly intiialized, even if not being used. In practice very few modules actually use this method, so by checking if the method is implemented before calling it, we can eliminate most of this work. (Hopefully in future we can get ride of this method altogether, but right now it's integral to the way that text layout is implemented). Reviewed By: majak, javache Differential Revision: D2982181 fb-gh-sync-id: 818d0aac61197df89263c919c2c80a003e293ac5 shipit-source-id: 818d0aac61197df89263c919c2c80a003e293ac5
1 parent c8835d0 commit f7df3bb

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

React/Modules/RCTUIManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ - (void)_layoutAndMount
963963
// Gather blocks to be executed now that all view hierarchy manipulations have
964964
// been completed (note that these may still take place before layout has finished)
965965
for (RCTComponentData *componentData in _componentDataByName.allValues) {
966-
RCTViewManagerUIBlock uiBlock = [componentData.manager uiBlockToAmendWithShadowViewRegistry:_shadowViewRegistry];
966+
RCTViewManagerUIBlock uiBlock = [componentData uiBlockToAmendWithShadowViewRegistry:_shadowViewRegistry];
967967
[self addUIBlock:uiBlock];
968968
}
969969

React/Views/RCTComponentData.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
#import "RCTComponent.h"
1313
#import "RCTDefines.h"
14+
#import "RCTViewManager.h"
1415

1516
@class RCTBridge;
1617
@class RCTShadowView;
17-
@class RCTViewManager;
1818
@class UIView;
1919

2020
@interface RCTComponentData : NSObject
@@ -33,4 +33,6 @@
3333

3434
- (NSDictionary<NSString *, id> *)viewConfig;
3535

36+
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NSNumber *, RCTShadowView *> *)registry;
37+
3638
@end

React/Views/RCTComponentData.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#import "RCTBridge.h"
1515
#import "RCTShadowView.h"
1616
#import "RCTUtils.h"
17-
#import "RCTViewManager.h"
1817
#import "UIView+React.h"
1918

2019
typedef void (^RCTPropBlock)(id<RCTComponent> view, id json);
@@ -44,6 +43,7 @@ @implementation RCTComponentData
4443
RCTShadowView *_defaultShadowView;
4544
NSMutableDictionary<NSString *, RCTPropBlock> *_viewPropBlocks;
4645
NSMutableDictionary<NSString *, RCTPropBlock> *_shadowPropBlocks;
46+
BOOL _implementsUIBlockToAmendWithShadowViewRegistry;
4747
__weak RCTBridge *_bridge;
4848
}
4949

@@ -63,6 +63,14 @@ - (instancetype)initWithManagerClass:(Class)managerClass
6363
if ([_name hasSuffix:@"Manager"]) {
6464
_name = [_name substringToIndex:_name.length - @"Manager".length];
6565
}
66+
67+
_implementsUIBlockToAmendWithShadowViewRegistry = NO;
68+
Class cls = _managerClass;
69+
while (cls != [RCTViewManager class]) {
70+
_implementsUIBlockToAmendWithShadowViewRegistry = _implementsUIBlockToAmendWithShadowViewRegistry ||
71+
RCTClassOverridesInstanceMethod(cls, @selector(uiBlockToAmendWithShadowViewRegistry:));
72+
cls = [cls superclass];
73+
}
6674
}
6775
return self;
6876
}
@@ -412,4 +420,12 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV
412420
};
413421
}
414422

423+
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NSNumber *,RCTShadowView *> *)registry
424+
{
425+
if (_implementsUIBlockToAmendWithShadowViewRegistry) {
426+
return [[self manager] uiBlockToAmendWithShadowViewRegistry:registry];
427+
}
428+
return nil;
429+
}
430+
415431
@end

0 commit comments

Comments
 (0)