From 793023a4e24e8a284af6a98b1420ef58e7ae6776 Mon Sep 17 00:00:00 2001 From: Zeya Peng Date: Thu, 26 Jun 2025 14:17:27 -0700 Subject: [PATCH] Fewer calls to direct manipulation callback (#52296) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52296 ## Changelog: [Internal] [Changed] - Fewer calls to direct manipulation callback `NativeAnimatedNodesManager::onRender` is supposed to run each frame for c++ animation, from the callstack sample trace, the vast majority of time is spent on `updateNodes` (run update on all AnimatedNodes) and `commitProps` (where either Fabric ShadowTree commit or direct manipulation is called). Change in this PR is supposed to reduce time spent in `commitProps` {F1979788964} Reviewed By: sammy-SC Differential Revision: D77380842 fbshipit-source-id: 2f25ca1fba4171a7b3e485298738379d0daff3ad --- .../renderer/animated/NativeAnimatedNodesManager.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp b/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp index a8d23f303fb..d71af0abffc 100644 --- a/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp +++ b/packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.cpp @@ -743,6 +743,9 @@ void NativeAnimatedNodesManager::schedulePropsCommit( (layoutStyleUpdated || forceFabricCommit || directManipulationCallback_ == nullptr)) { mergeObjects(updateViewProps_[viewTag], props); + + // Must call direct manipulation to set final values on components. + mergeObjects(updateViewPropsDirect_[viewTag], props); } else if (directManipulationCallback_ != nullptr) { mergeObjects(updateViewPropsDirect_[viewTag], props); } @@ -811,12 +814,6 @@ bool NativeAnimatedNodesManager::commitProps() { if (fabricCommitCallback_ != nullptr) { if (!updateViewProps_.empty()) { - // Must call direct manipulation to set final values on components. - if (directManipulationCallback_ != nullptr) { - for (const auto& [viewTag, props] : updateViewProps_) { - directManipulationCallback_(viewTag, folly::dynamic(props)); - } - } fabricCommitCallback_(updateViewProps_); updateViewProps_.clear(); }