From 39d50f9f32f98cf9a2fd32cd1548345a8b6df104 Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Sat, 12 Nov 2022 04:17:11 +0100 Subject: [PATCH] Delete preemtive view allocation on iOS (#1495) Summary: changelog: [internal] preemtive view allocation has been disabled on iOS for over a year. We kept the code in but didn't do anything with it. This diff removes the code and related mobile config. Post where we decided to turn preemtive view allocation off: https://fb.workplace.com/groups/215742978987717/permalink/832644567297552/ jest_e2e[run_all_tests] Reviewed By: mdvacca Differential Revision: D37922589 fbshipit-source-id: 1af8949cbbd9d48a2d80ca238b280178cbe2ead5 Co-authored-by: Samuel Susla --- React/Base/RCTConstants.h | 6 --- React/Base/RCTConstants.m | 15 ------- .../Mounting/RCTComponentViewFactory.mm | 7 ---- .../Mounting/RCTComponentViewRegistry.h | 5 --- .../Mounting/RCTComponentViewRegistry.mm | 39 ------------------- React/Fabric/RCTSurfacePresenter.mm | 4 -- .../Mounting/RCTComponentViewRegistryTests.mm | 1 + 7 files changed, 1 insertion(+), 76 deletions(-) diff --git a/React/Base/RCTConstants.h b/React/Base/RCTConstants.h index cc51b2e780f2cb..d5887e267999f5 100644 --- a/React/Base/RCTConstants.h +++ b/React/Base/RCTConstants.h @@ -10,12 +10,6 @@ RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotification; RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey; -/* - * Preemptive View Allocation - */ -RCT_EXTERN BOOL RCTExperimentGetPreemptiveViewAllocationDisabled(void); -RCT_EXTERN void RCTExperimentSetPreemptiveViewAllocationDisabled(BOOL value); - /* * W3C Pointer Events */ diff --git a/React/Base/RCTConstants.m b/React/Base/RCTConstants.m index 75b76d708f7519..f03cb16514ae93 100644 --- a/React/Base/RCTConstants.m +++ b/React/Base/RCTConstants.m @@ -10,21 +10,6 @@ NSString *const RCTUserInterfaceStyleDidChangeNotification = @"RCTUserInterfaceStyleDidChangeNotification"; NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollectionKey = @"traitCollection"; -/* - * Preemptive View Allocation - */ -static BOOL RCTExperimentPreemptiveViewAllocationDisabled = NO; - -BOOL RCTExperimentGetPreemptiveViewAllocationDisabled() -{ - return RCTExperimentPreemptiveViewAllocationDisabled; -} - -void RCTExperimentSetPreemptiveViewAllocationDisabled(BOOL value) -{ - RCTExperimentPreemptiveViewAllocationDisabled = value; -} - /* * W3C Pointer Events */ diff --git a/React/Fabric/Mounting/RCTComponentViewFactory.mm b/React/Fabric/Mounting/RCTComponentViewFactory.mm index 1487beaa2a92ce..5656b857718411 100644 --- a/React/Fabric/Mounting/RCTComponentViewFactory.mm +++ b/React/Fabric/Mounting/RCTComponentViewFactory.mm @@ -71,13 +71,6 @@ + (RCTComponentViewFactory *)currentComponentViewFactory dispatch_once(&onceToken, ^{ componentViewFactory = [RCTComponentViewFactory new]; [componentViewFactory registerComponentViewClass:[RCTRootComponentView class]]; - [componentViewFactory registerComponentViewClass:[RCTViewComponentView class]]; - [componentViewFactory registerComponentViewClass:[RCTParagraphComponentView class]]; - [componentViewFactory registerComponentViewClass:[RCTTextInputComponentView class]]; - - Class imageClass = RCTComponentViewClassWithName("Image"); - [componentViewFactory registerComponentViewClass:imageClass]; - componentViewFactory->_providerRegistry.setComponentDescriptorProviderRequest( [](ComponentName requestedComponentName) { [componentViewFactory registerComponentIfPossible:requestedComponentName]; diff --git a/React/Fabric/Mounting/RCTComponentViewRegistry.h b/React/Fabric/Mounting/RCTComponentViewRegistry.h index bcf78a20ccd236..884424aa6a63ae 100644 --- a/React/Fabric/Mounting/RCTComponentViewRegistry.h +++ b/React/Fabric/Mounting/RCTComponentViewRegistry.h @@ -50,11 +50,6 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable UIView *)findComponentViewWithTag:(facebook::react::Tag)tag; -/** - * Creates a component view with a given type and puts it to the recycle pool. - */ -- (void)optimisticallyCreateComponentViewWithComponentHandle:(facebook::react::ComponentHandle)componentHandle; - @end NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/RCTComponentViewRegistry.mm b/React/Fabric/Mounting/RCTComponentViewRegistry.mm index afd8024939f74a..b748c05f5a59fc 100644 --- a/React/Fabric/Mounting/RCTComponentViewRegistry.mm +++ b/React/Fabric/Mounting/RCTComponentViewRegistry.mm @@ -35,42 +35,11 @@ - (instancetype)init selector:@selector(handleApplicationDidReceiveMemoryWarningNotification) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; - - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - // Calling this a bit later, when the main thread is probably idle while JavaScript thread is busy. - [self preallocateViewComponents]; - }); } return self; } -- (void)preallocateViewComponents -{ - if (RCTExperimentGetPreemptiveViewAllocationDisabled()) { - return; - } - - // This data is based on empirical evidence which should represent the reality pretty well. - // Regular `` has magnitude equals to `1` by definition. - std::vector> componentMagnitudes = { - {[RCTViewComponentView componentDescriptorProvider].handle, 1}, - {[RCTImageComponentView componentDescriptorProvider].handle, 0.3}, - {[RCTParagraphComponentView componentDescriptorProvider].handle, 0.3}, - }; - - // `complexity` represents the complexity of a typical surface in a number of `` components (with Flattening - // enabled). - float complexity = 100; - - // The whole process should not take more than 10ms in the worst case, so there is no need to split it up. - for (const auto &componentMagnitude : componentMagnitudes) { - for (int i = 0; i < complexity * componentMagnitude.second; i++) { - [self optimisticallyCreateComponentViewWithComponentHandle:componentMagnitude.first]; - } - } -} - - (RCTComponentViewDescriptor const &)dequeueComponentViewWithComponentHandle:(ComponentHandle)componentHandle tag:(Tag)tag { @@ -100,14 +69,6 @@ - (void)enqueueComponentViewWithComponentHandle:(ComponentHandle)componentHandle [self _enqueueComponentViewWithComponentHandle:componentHandle componentViewDescriptor:componentViewDescriptor]; } -- (void)optimisticallyCreateComponentViewWithComponentHandle:(ComponentHandle)componentHandle -{ - RCTAssertMainQueue(); - [self _enqueueComponentViewWithComponentHandle:componentHandle - componentViewDescriptor:[self.componentViewFactory - createComponentViewWithComponentHandle:componentHandle]]; -} - - (RCTComponentViewDescriptor const &)componentViewDescriptorWithTag:(Tag)tag { RCTAssertMainQueue(); diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 8af74f8588ab0b..89e6840ea0ffaa 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -252,10 +252,6 @@ - (RCTScheduler *)_createScheduler { auto reactNativeConfig = _contextContainer->at>("ReactNativeConfig"); - if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:preemptive_view_allocation_disabled_ios")) { - RCTExperimentSetPreemptiveViewAllocationDisabled(YES); - } - if (reactNativeConfig && reactNativeConfig->getBool("rn_convergence:dispatch_pointer_events")) { RCTSetDispatchW3CPointerEvents(YES); } diff --git a/React/Tests/Mounting/RCTComponentViewRegistryTests.mm b/React/Tests/Mounting/RCTComponentViewRegistryTests.mm index 9bb5484a4c5cb0..4bd2b6529aad31 100644 --- a/React/Tests/Mounting/RCTComponentViewRegistryTests.mm +++ b/React/Tests/Mounting/RCTComponentViewRegistryTests.mm @@ -22,6 +22,7 @@ - (void)setUp { [super setUp]; _componentViewRegistry = [RCTComponentViewRegistry new]; + [_componentViewRegistry.componentViewFactory registerComponentViewClass:[RCTViewComponentView class]]; } - (void)testComponentViewDescriptorWithTag