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

Optimize Shadow Tree cloning #6214

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit(
// ShadowTree not commited by Reanimated, apply updates from PropsRegistry

auto rootNode = newRootShadowNode->ShadowNode::clone(ShadowNodeFragment{});
PropsMap propsMap;
PropsMap<FollyDynamicPropsWrapper> propsMap;

{
auto lock = propsRegistry_->createLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

namespace reanimated {

template<Derived T>
ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive(
const ChildrenMap &childrenMap,
const ShadowNode::Shared &shadowNode,
const PropsMap &propsMap) {
const PropsMap<T> &propsMap) {
const auto family = &shadowNode->getFamily();
const auto affectedChildrenIt = childrenMap.find(family);
const auto propsIt = propsMap.find(family);
Expand Down Expand Up @@ -42,9 +43,10 @@ ShadowNode::Unshared cloneShadowTreeWithNewPropsRecursive(
return result;
}

template<Derived T>
ShadowNode::Unshared cloneShadowTreeWithNewProps(
const ShadowNode::Shared &oldRootNode,
const PropsMap &propsMap) {
const PropsMap<T> &propsMap) {
ChildrenMap childrenMap;

for (auto &[family, _] : propsMap) {
Expand All @@ -68,6 +70,14 @@ ShadowNode::Unshared cloneShadowTreeWithNewProps(
childrenMap, oldRootNode, propsMap);
}

template ShadowNode::Unshared cloneShadowTreeWithNewProps(
const ShadowNode::Shared &oldRootNode,
const PropsMap<JsiValuePropsWrapper> &propsMap);

template ShadowNode::Unshared cloneShadowTreeWithNewProps(
const ShadowNode::Shared &oldRootNode,
const PropsMap<FollyDynamicPropsWrapper> &propsMap);

} // namespace reanimated

#endif // RCT_NEW_ARCH_ENABLED
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/uimanager/UIManager.h>

#include <type_traits>
#include <memory>
#include <unordered_map>
#include <vector>
Expand All @@ -15,12 +16,18 @@ using namespace react;

namespace reanimated {

using PropsMap = std::unordered_map<const ShadowNodeFamily *, std::vector<std::unique_ptr<PropsWrapper>>>;
template<class T>
concept Derived = std::is_base_of_v<PropsWrapper, T>;

template<Derived T>
using PropsMap = std::unordered_map<const ShadowNodeFamily *, std::vector<std::unique_ptr<T>>>;

using ChildrenMap = std::unordered_map<const ShadowNodeFamily *, std::vector<int>>;

template<Derived T>
ShadowNode::Unshared cloneShadowTreeWithNewProps(
const ShadowNode::Shared &oldRootNode,
const PropsMap &propsMap);
const PropsMap<T> &propsMap);

} // namespace reanimated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ void NativeReanimatedModule::performOperations() {
shadowTree.commit(
[&](RootShadowNode const &oldRootShadowNode)
-> RootShadowNode::Unshared {
PropsMap propsMap;
PropsMap<JsiValuePropsWrapper> propsMap;
auto rootNode =
oldRootShadowNode.ShadowNode::clone(ShadowNodeFragment{});
for (auto &[shadowNode, props] : copiedOperationsQueue) {
Expand Down
Loading