Skip to content

Commit

Permalink
Delete preemtive view allocation on iOS (microsoft#1495)
Browse files Browse the repository at this point in the history
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 <samuelsusla@fb.com>
  • Loading branch information
2 people authored and Shawn Dempsey committed Mar 10, 2023
1 parent 587a2ed commit 39d50f9
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 76 deletions.
6 changes: 0 additions & 6 deletions React/Base/RCTConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
15 changes: 0 additions & 15 deletions React/Base/RCTConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
7 changes: 0 additions & 7 deletions React/Fabric/Mounting/RCTComponentViewFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<RCTComponentViewProtocol> imageClass = RCTComponentViewClassWithName("Image");
[componentViewFactory registerComponentViewClass:imageClass];

componentViewFactory->_providerRegistry.setComponentDescriptorProviderRequest(
[](ComponentName requestedComponentName) {
[componentViewFactory registerComponentIfPossible:requestedComponentName];
Expand Down
5 changes: 0 additions & 5 deletions React/Fabric/Mounting/RCTComponentViewRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (nullable UIView<RCTComponentViewProtocol> *)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
39 changes: 0 additions & 39 deletions React/Fabric/Mounting/RCTComponentViewRegistry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<View>` has magnitude equals to `1` by definition.
std::vector<std::pair<ComponentHandle, float>> 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 `<View>` 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
{
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ - (RCTScheduler *)_createScheduler
{
auto reactNativeConfig = _contextContainer->at<std::shared_ptr<ReactNativeConfig const>>("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);
}
Expand Down
1 change: 1 addition & 0 deletions React/Tests/Mounting/RCTComponentViewRegistryTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ - (void)setUp
{
[super setUp];
_componentViewRegistry = [RCTComponentViewRegistry new];
[_componentViewRegistry.componentViewFactory registerComponentViewClass:[RCTViewComponentView class]];
}

- (void)testComponentViewDescriptorWithTag
Expand Down

0 comments on commit 39d50f9

Please sign in to comment.