Skip to content

Commit bd58c71

Browse files
Bartlomiej Bloniarzmeta-codesync[bot]
authored andcommitted
Use batched buffer packing in synchronouslyUpdateProps on C++ side
Summary: Pack animated property updates into a compact byte+double buffer format in C++ and add the corresponding Java-side buffer decoder. This avoids per-property JNI calls by batching all updates into a single cross-boundary transfer. Gated behind the `optimizedAnimatedPropUpdates` feature flag. Changelog: [Android][Changed] - Pack animated prop updates from the C++ animation backend into a single byte+double buffer instead of issuing one JNI call per property (gated by `optimizedAnimatedPropUpdates`) Differential Revision: D101157452
1 parent 07137c2 commit bd58c71

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropSerializer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ void packBackfaceVisibility(
559559
}
560560
dyn.insert("backfaceVisibility", visibilityStr);
561561
}
562-
563562
void packAnimatedProp(
564563
folly::dynamic& dyn,
565564
const std::unique_ptr<AnimatedPropBase>& animatedProp) {

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <react/debug/react_native_assert.h>
1212
#include <react/featureflags/ReactNativeFeatureFlags.h>
1313
#include <react/renderer/animationbackend/AnimatedPropsSerializer.h>
14-
#include <react/renderer/graphics/Color.h>
1514
#include <chrono>
1615
#include <utility>
1716

@@ -85,7 +84,7 @@ void AnimationBackend::applySurfaceUpdates(
8584
if (updates.hasLayoutUpdates) {
8685
commitUpdates(surfaceId, updates);
8786
} else {
88-
synchronouslyUpdateProps(updates.propsMap);
87+
synchronouslyUpdateProps(surfaceId, updates.propsMap);
8988
}
9089
}
9190

@@ -194,18 +193,28 @@ void AnimationBackend::commitUpdates(
194193
});
195194
}
196195

197-
void AnimationBackend::synchronouslyUpdateProps(
196+
void AnimationBackend::synchronouslyUpdatePropsUnbuffered(
198197
const std::unordered_map<Tag, AnimatedProps>& updates) {
199198
for (auto& [tag, animatedProps] : updates) {
200-
// TODO: We shouldn't repack it into dynamic, but for that a rewrite
201-
// of synchronouslyUpdateViewOnUIThread is needed
202199
auto dyn = animationbackend::packAnimatedProps(animatedProps);
203200
if (auto uiManager = uiManager_.lock()) {
204201
uiManager->synchronouslyUpdateViewOnUIThread(tag, dyn);
205202
}
206203
}
207204
}
208205

206+
void AnimationBackend::synchronouslyUpdateProps(
207+
SurfaceId surfaceId,
208+
const std::unordered_map<Tag, AnimatedProps>& updates) {
209+
if (ReactNativeFeatureFlags::optimizedAnimatedPropUpdates()) {
210+
if (auto uiManager = uiManager_.lock()) {
211+
uiManager->synchronouslyUpdateAnimatedPropsOnUIThread(surfaceId, updates);
212+
}
213+
return;
214+
}
215+
synchronouslyUpdatePropsUnbuffered(updates);
216+
}
217+
209218
void AnimationBackend::requestAsyncFlushForSurfaces(
210219
const std::set<SurfaceId>& surfaces) {
211220
react_native_assert(

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimationBackend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class AnimationBackend : public UIManagerAnimationBackend {
5252
std::shared_ptr<AnimationChoreographer> animationChoreographer,
5353
std::shared_ptr<UIManager> uiManager);
5454
void commitUpdates(SurfaceId surfaceId, SurfaceUpdates &surfaceUpdates);
55-
void synchronouslyUpdateProps(const std::unordered_map<Tag, AnimatedProps> &updates);
55+
void synchronouslyUpdateProps(SurfaceId surfaceId, const std::unordered_map<Tag, AnimatedProps> &updates);
56+
void synchronouslyUpdatePropsUnbuffered(const std::unordered_map<Tag, AnimatedProps> &updates);
5657
void requestAsyncFlushForSurfaces(const std::set<SurfaceId> &surfaces);
5758
void clearRegistry(SurfaceId surfaceId) override;
5859
void clearRegistryOnSurfaceStop(SurfaceId surfaceId) override;

0 commit comments

Comments
 (0)