-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use commit hook to update props on Fabric #4075
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Would be even better if you could write 2-3 sentences in the description to explain how this new approach works.
@@ -43,7 +42,8 @@ - (void)_tryAndHandleError:(dispatch_block_t)block; | |||
@implementation REAModule { | |||
#ifdef RCT_NEW_ARCH_ENABLED | |||
__weak RCTSurfacePresenter *_surfacePresenter; | |||
std::shared_ptr<NewestShadowNodesRegistry> newestShadowNodesRegistry; | |||
std::shared_ptr<PropsRegistry> propsRegistry_; | |||
std::shared_ptr<ReanimatedCommitHook> commitHook_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to retain commitHook as a class member here? Looks like it is not being used except from passing it to uimanager. Same applies in NativeProxy implementation for Android
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to store it because React Native's UIManager
keeps a vector of raw pointers (see here).
Summary
This draft PR introduces a new approach towards updating layout props on Fabric that uses
UIManagerCommitHook
. Previously, we would keep a registry of most recent ShadowNodes. Each time RN or Reanimated cloned a ShadowNode, we would retrieve the most recent version of it from the registry as well as store the new copy. Obviously, this required synchronization at the level of eachcloneNode
call so rendering large trees was slow. The new approach stores all most recent props of animated components inPropsRegistry
and applies them on each RN render usingReanimatedCommitHook
all at once which improves the performance significantly.Changes:
ReanimatedUIManagerBinding
ReanimatedCommitHook
NewestShadowNodesRegistry
intoPropsRegistry
_removeShadowNodeFromRegistry
into_removeFromPropsRegistry
Requires:
Things to consider:
ReanimatedCommitHook
handle all updates instead of callingisThereAnyLayoutProp
, enqueuing update inoperationsInBatch_
and updatinglastReanimatedRoot
but modifying only necessary ShadowNodes?propsRegistry.map_
inReanimatedCommitHook
to prevent locking the UI thread while the background thread runs the commit hook?Detected problems:
Review
Since this PR affects 31 files, it is recommended to review the commits one-by-one.
Test plan
Launch FabricExample and open the following examples: chessboard, width, ref