Skip to content
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

Batch remove from props registry #4678

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

tomekzaw
Copy link
Member

@tomekzaw tomekzaw commented Jul 6, 2023

Summary

This PR addresses the following TODO:

// TODO: batching
runOnUI(() => {
_removeFromPropsRegistry!(viewTag);
})();

Previously, we would schedule a worklet via runOnJS for each individual unmounted animated component. Each worklet would call JSI binding _removeFromPropsRegistry. This PR adds batching layer on JS context and changes the semantics of _removeFromPropsRegistry so that it accepts an array of view tags to remove from PropsRegistry.

Test plan

PropsRegistry.cpp

 #ifdef RCT_NEW_ARCH_ENABLED
 
 #include "PropsRegistry.h"
 
+#include <iostream>
 
 namespace reanimated {
 
 std::lock_guard<std::mutex> PropsRegistry::createLock() const {
+  {
+    std::lock_guard<std::mutex> lock(mutex_);
+    std::cout << "map_.size() = " << map_.size() << std::endl;
+  }
   return std::lock_guard<std::mutex>(mutex_);
 }

PropsRegistry.ts

 function flush() {
   if (__DEV__ && !global._IS_FABRIC) {
     throw new Error('PropsRegistry is only available on Fabric');
   }
+  console.log(viewTags.length);
   runOnUI(removeFromPropsRegistryOnUI)(viewTags);
   viewTags = [];
 }

FabricExample → ChessboardExample.tsx

Zrzut ekranu 2023-07-6 o 15 54 01

@tomekzaw tomekzaw requested a review from piaskowyk July 6, 2023 13:56
Copy link
Contributor

@tjzel tjzel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems mergeleable to me 👍

@tomekzaw tomekzaw added this pull request to the merge queue Jul 6, 2023
Merged via the queue into main with commit 04bd8e1 Jul 6, 2023
9 checks passed
@tomekzaw tomekzaw deleted the @tomekzaw/batch-remove-from-props-registry branch July 6, 2023 15:10
Latropos pushed a commit that referenced this pull request Jul 13, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

This PR addresses the following TODO:


https://github.com/software-mansion/react-native-reanimated/blob/1359a1141ddd538b42d3c6db51d3e7c6fb586fd7/src/createAnimatedComponent.tsx#L363-L366

Previously, we would schedule a worklet via `runOnJS` for each
individual unmounted animated component. Each worklet would call JSI
binding `_removeFromPropsRegistry`. This PR adds batching layer on JS
context and changes the semantics of `_removeFromPropsRegistry` so that
it accepts an array of view tags to remove from PropsRegistry.

## Test plan

`PropsRegistry.cpp`

```diff
 #ifdef RCT_NEW_ARCH_ENABLED
 
 #include "PropsRegistry.h"
 
+#include <iostream>
 
 namespace reanimated {
 
 std::lock_guard<std::mutex> PropsRegistry::createLock() const {
+  {
+    std::lock_guard<std::mutex> lock(mutex_);
+    std::cout << "map_.size() = " << map_.size() << std::endl;
+  }
   return std::lock_guard<std::mutex>(mutex_);
 }
```

`PropsRegistry.ts`

```diff
 function flush() {
   if (__DEV__ && !global._IS_FABRIC) {
     throw new Error('PropsRegistry is only available on Fabric');
   }
+  console.log(viewTags.length);
   runOnUI(removeFromPropsRegistryOnUI)(viewTags);
   viewTags = [];
 }
```

FabricExample &rarr; ChessboardExample.tsx

<img width="114" alt="Zrzut ekranu 2023-07-6 o 15 54 01"
src="https://github.com/software-mansion/react-native-reanimated/assets/20516055/005b52f9-45c5-4db9-a4fd-964793dbf66c">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants