Skip to content

Commit 2166d2b

Browse files
sherginfacebook-github-bot
authored andcommitted
Fabric: Trivial implementation of prelumiary view allocation on iOS
Summary: @public We have this feature in the current version of RN, so it would be nice to support that in Fabric as well. This should save us tens of ms of views creation during mounting. And that's quite easy to do! Reviewed By: fkgozali Differential Revision: D8701992 fbshipit-source-id: 4e3049df009ffd65bb43043de388e81795e5e559
1 parent 5d9326b commit 2166d2b

6 files changed

+34
-4
lines changed

React/Fabric/Mounting/RCTComponentViewRegistry.h

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ NS_ASSUME_NONNULL_BEGIN
4343
*/
4444
- (ReactTag)tagByComponentView:(UIView<RCTComponentViewProtocol> *)componentView;
4545

46+
/**
47+
* Creates a component view with a given type and puts it to the recycle pool.
48+
*/
49+
- (void)preliminaryCreateComponentViewWithName:(NSString *)componentName;
50+
4651
@end
4752

4853
NS_ASSUME_NONNULL_END

React/Fabric/Mounting/RCTComponentViewRegistry.mm

+8-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ + (void)unregisterView:(UIView *)view
6464

6565
#endif
6666

67-
const NSInteger RCTComponentViewRegistryRecyclePoolMaxSize = 256;
67+
const NSInteger RCTComponentViewRegistryRecyclePoolMaxSize = 1024;
6868

6969
@implementation RCTComponentViewRegistry {
7070
NSMapTable<id, UIView<RCTComponentViewProtocol> *> *_registry;
@@ -121,6 +121,13 @@ - (void)enqueueComponentViewWithName:(NSString *)componentName
121121
[self _enqueueComponentViewWithName:componentName componentView:componentView];
122122
}
123123

124+
- (void)preliminaryCreateComponentViewWithName:(NSString *)componentName
125+
{
126+
RCTAssertMainQueue();
127+
[self _enqueueComponentViewWithName:componentName
128+
componentView:[self _createComponentViewWithName:componentName]];
129+
}
130+
124131
- (UIView<RCTComponentViewProtocol> *)componentViewByTag:(ReactTag)tag
125132
{
126133
RCTAssertMainQueue();

React/Fabric/Mounting/RCTMountingManager.h

+8
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ NS_ASSUME_NONNULL_BEGIN
2626
/**
2727
* Transfroms mutation insturctions to mount items and execute them.
2828
* The order of mutation tnstructions matters.
29+
* Can be called from any thread.
2930
*/
3031
- (void)mutateComponentViewTreeWithMutationInstructions:(facebook::react::TreeMutationInstructionList)instructions
3132
rootTag:(ReactTag)rootTag;
3233

34+
/**
35+
* Suggests preliminary creation of a component view of given type.
36+
* The receiver is free to ignore the request.
37+
* Can be called from any thread.
38+
*/
39+
- (void)preliminaryCreateComponentViewWithName:(NSString *)componentName;
40+
3341
@end
3442

3543
NS_ASSUME_NONNULL_END

React/Fabric/Mounting/RCTMountingManager.mm

+7
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,11 @@ - (void)_performMountItems:(NSArray<RCTMountItemProtocol> *)mountItems
181181
[self.delegate mountingManager:self didMountComponentsWithRootTag:rootTag];
182182
}
183183

184+
- (void)preliminaryCreateComponentViewWithName:(NSString *)componentName
185+
{
186+
RCTExecuteOnMainQueue(^{
187+
[self->_componentViewRegistry preliminaryCreateComponentViewWithName:componentName];
188+
});
189+
}
190+
184191
@end

React/Fabric/RCTScheduler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
1919
@class RCTMountingManager;
2020

2121
/**
22-
* Exacly same semantic as `facebook::react::SchedulerDelegate`.
22+
* Exactly same semantic as `facebook::react::SchedulerDelegate`.
2323
*/
2424
@protocol RCTSchedulerDelegate
2525

React/Fabric/RCTSurfacePresenter.mm

+5-2
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,18 @@ - (void)dealloc
6767
[[NSNotificationCenter defaultCenter] removeObserver:self];
6868
}
6969

70-
- (void)schedulerDidComputeMutationInstructions:(facebook::react::TreeMutationInstructionList)instructions rootTag:(ReactTag)rootTag
70+
#pragma mark - RCTSchedulerDelegate
71+
72+
- (void)schedulerDidComputeMutationInstructions:(facebook::react::TreeMutationInstructionList)instructions
73+
rootTag:(ReactTag)rootTag
7174
{
7275
[_mountingManager mutateComponentViewTreeWithMutationInstructions:instructions
7376
rootTag:rootTag];
7477
}
7578

7679
- (void)schedulerDidRequestPreliminaryViewAllocationWithComponentName:(NSString *)componentName
7780
{
78-
// TODO: To be implemeted.
81+
[_mountingManager preliminaryCreateComponentViewWithName:componentName];
7982
}
8083

8184
#pragma mark - Internal Surface-dedicated Interface

0 commit comments

Comments
 (0)