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
This commit is contained in:
parent
c8835d0226
commit
f7df3bb78a
|
@ -963,7 +963,7 @@ RCT_EXPORT_METHOD(dispatchViewManagerCommand:(nonnull NSNumber *)reactTag
|
|||
// Gather blocks to be executed now that all view hierarchy manipulations have
|
||||
// been completed (note that these may still take place before layout has finished)
|
||||
for (RCTComponentData *componentData in _componentDataByName.allValues) {
|
||||
RCTViewManagerUIBlock uiBlock = [componentData.manager uiBlockToAmendWithShadowViewRegistry:_shadowViewRegistry];
|
||||
RCTViewManagerUIBlock uiBlock = [componentData uiBlockToAmendWithShadowViewRegistry:_shadowViewRegistry];
|
||||
[self addUIBlock:uiBlock];
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
#import "RCTComponent.h"
|
||||
#import "RCTDefines.h"
|
||||
#import "RCTViewManager.h"
|
||||
|
||||
@class RCTBridge;
|
||||
@class RCTShadowView;
|
||||
@class RCTViewManager;
|
||||
@class UIView;
|
||||
|
||||
@interface RCTComponentData : NSObject
|
||||
|
@ -33,4 +33,6 @@
|
|||
|
||||
- (NSDictionary<NSString *, id> *)viewConfig;
|
||||
|
||||
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NSNumber *, RCTShadowView *> *)registry;
|
||||
|
||||
@end
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#import "RCTBridge.h"
|
||||
#import "RCTShadowView.h"
|
||||
#import "RCTUtils.h"
|
||||
#import "RCTViewManager.h"
|
||||
#import "UIView+React.h"
|
||||
|
||||
typedef void (^RCTPropBlock)(id<RCTComponent> view, id json);
|
||||
|
@ -44,6 +43,7 @@ typedef void (^RCTPropBlock)(id<RCTComponent> view, id json);
|
|||
RCTShadowView *_defaultShadowView;
|
||||
NSMutableDictionary<NSString *, RCTPropBlock> *_viewPropBlocks;
|
||||
NSMutableDictionary<NSString *, RCTPropBlock> *_shadowPropBlocks;
|
||||
BOOL _implementsUIBlockToAmendWithShadowViewRegistry;
|
||||
__weak RCTBridge *_bridge;
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,14 @@ typedef void (^RCTPropBlock)(id<RCTComponent> view, id json);
|
|||
if ([_name hasSuffix:@"Manager"]) {
|
||||
_name = [_name substringToIndex:_name.length - @"Manager".length];
|
||||
}
|
||||
|
||||
_implementsUIBlockToAmendWithShadowViewRegistry = NO;
|
||||
Class cls = _managerClass;
|
||||
while (cls != [RCTViewManager class]) {
|
||||
_implementsUIBlockToAmendWithShadowViewRegistry = _implementsUIBlockToAmendWithShadowViewRegistry ||
|
||||
RCTClassOverridesInstanceMethod(cls, @selector(uiBlockToAmendWithShadowViewRegistry:));
|
||||
cls = [cls superclass];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -412,4 +420,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
};
|
||||
}
|
||||
|
||||
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NSNumber *,RCTShadowView *> *)registry
|
||||
{
|
||||
if (_implementsUIBlockToAmendWithShadowViewRegistry) {
|
||||
return [[self manager] uiBlockToAmendWithShadowViewRegistry:registry];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue