Skip to content

Commit 1071beb

Browse files
Bartlomiej Bloniarzmeta-codesync[bot]
authored andcommitted
Add tracing instrumentation to shared animation backend
Summary: Add TraceSection annotations to the shared animated backend so the work it performs becomes visible in systrace / Perfetto / Android Studio System Trace captures. Instrumented entry points: - AnimationBackend::onAnimationFrame - AnimationBackend::applySurfaceUpdates - AnimationBackend::commitUpdates - AnimationBackend::synchronouslyUpdateProps and its three platform variants (Buffered, Unbuffered, WithAnimatedProps) - AnimationBackend::requestAsyncFlushForSurfaces - AnimationBackendCommitHook::shadowTreeWillCommit - AnimatedPropsRegistry::update - AnimatedPropsRegistry::getMap Each section includes contextual args (surfaceId / surface count / update count) where available to make traces easier to correlate when investigating animation perf. Changelog: [General][Added] - Add `TraceSection` instrumentation to the shared animation backend so its work shows up in systrace / Perfetto / Android Studio System Trace captures Reviewed By: christophpurrer Differential Revision: D102800179
1 parent a125c84 commit 1071beb

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
*/
77

88
#include "AnimatedPropsRegistry.h"
9+
#include <cxxreact/TraceSection.h>
910
#include <react/renderer/core/PropsParserContext.h>
1011
#include "AnimatedProps.h"
1112

1213
namespace facebook::react {
1314

1415
void AnimatedPropsRegistry::update(
1516
const std::unordered_map<SurfaceId, SurfaceUpdates>& surfaceUpdates) {
17+
TraceSection s(
18+
"AnimatedPropsRegistry::update", "surfaceCount", surfaceUpdates.size());
1619
auto lock = std::lock_guard(mutex_);
1720
for (const auto& [surfaceId, updates] : surfaceUpdates) {
1821
auto& surfaceContext = surfaceContexts_[surfaceId];
@@ -59,6 +62,7 @@ std::pair<
5962
std::unordered_set<std::shared_ptr<const ShadowNodeFamily>>&,
6063
SnapshotMap&>
6164
AnimatedPropsRegistry::getMap(SurfaceId surfaceId) {
65+
TraceSection s("AnimatedPropsRegistry::getMap", "surfaceId", surfaceId);
6266
auto lock = std::lock_guard(mutex_);
6367
auto& [pendingMap, map, pendingFamilies, families] =
6468
surfaceContexts_[surfaceId];

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "AnimationBackend.h"
99
#include "AnimatedPropsRegistry.h"
1010

11+
#include <cxxreact/TraceSection.h>
1112
#include <react/debug/react_native_assert.h>
1213
#include <react/featureflags/ReactNativeFeatureFlags.h>
1314
#include <react/renderer/animationbackend/AnimatedPropsSerializer.h>
@@ -78,6 +79,10 @@ void AnimationBackend::unpackMutations(
7879
void AnimationBackend::applySurfaceUpdates(
7980
std::unordered_map<SurfaceId, SurfaceUpdates>& surfaceUpdates,
8081
const std::set<SurfaceId>& asyncFlushSurfaces) {
82+
TraceSection s(
83+
"AnimationBackend::applySurfaceUpdates",
84+
"surfaceCount",
85+
surfaceUpdates.size());
8186
animatedPropsRegistry_->update(surfaceUpdates);
8287

8388
for (auto& [surfaceId, updates] : surfaceUpdates) {
@@ -99,6 +104,7 @@ void AnimationBackend::applyMutations(AnimationMutations mutations) {
99104
}
100105

101106
void AnimationBackend::onAnimationFrame(AnimationTimestamp timestamp) {
107+
TraceSection s("AnimationBackend::onAnimationFrame");
102108
std::vector<CallbackWithId> callbacksCopy;
103109

104110
{
@@ -158,6 +164,12 @@ void AnimationBackend::pushAnimationMutations(const Callback& callback) {
158164
void AnimationBackend::commitUpdates(
159165
SurfaceId surfaceId,
160166
SurfaceUpdates& surfaceUpdates) {
167+
TraceSection s(
168+
"AnimationBackend::commitUpdates",
169+
"surfaceId",
170+
surfaceId,
171+
"updateCount",
172+
surfaceUpdates.propsMap.size());
161173
auto uiManager = uiManager_.lock();
162174
if (!uiManager) {
163175
return;
@@ -195,6 +207,10 @@ void AnimationBackend::commitUpdates(
195207

196208
void AnimationBackend::synchronouslyUpdatePropsUnbuffered(
197209
const std::unordered_map<Tag, AnimatedProps>& updates) {
210+
TraceSection s(
211+
"AnimationBackend::synchronouslyUpdatePropsUnbuffered",
212+
"updateCount",
213+
updates.size());
198214
for (auto& [tag, animatedProps] : updates) {
199215
auto dyn = animationbackend::packAnimatedProps(animatedProps);
200216
if (auto uiManager = uiManager_.lock()) {
@@ -206,6 +222,12 @@ void AnimationBackend::synchronouslyUpdatePropsUnbuffered(
206222
void AnimationBackend::synchronouslyUpdateProps(
207223
SurfaceId surfaceId,
208224
const std::unordered_map<Tag, AnimatedProps>& updates) {
225+
TraceSection s(
226+
"AnimationBackend::synchronouslyUpdateProps",
227+
"surfaceId",
228+
surfaceId,
229+
"updateCount",
230+
updates.size());
209231
if (ReactNativeFeatureFlags::optimizedAnimatedPropUpdates()) {
210232
if (auto uiManager = uiManager_.lock()) {
211233
uiManager->synchronouslyUpdateAnimatedPropsOnUIThread(surfaceId, updates);
@@ -217,6 +239,10 @@ void AnimationBackend::synchronouslyUpdateProps(
217239

218240
void AnimationBackend::requestAsyncFlushForSurfaces(
219241
const std::set<SurfaceId>& surfaces) {
242+
TraceSection s(
243+
"AnimationBackend::requestAsyncFlushForSurfaces",
244+
"surfaceCount",
245+
surfaces.size());
220246
react_native_assert(
221247
jsInvoker_ != nullptr ||
222248
surfaces.empty() && "jsInvoker_ was not provided");

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <react/renderer/animationbackend/AnimationBackendCommitHook.h>
99

10+
#include <cxxreact/TraceSection.h>
1011
#include <utility>
1112

1213
namespace facebook::react {
@@ -23,6 +24,10 @@ RootShadowNode::Unshared AnimationBackendCommitHook::shadowTreeWillCommit(
2324
const RootShadowNode::Shared& oldRootShadowNode,
2425
const RootShadowNode::Unshared& newRootShadowNode,
2526
const ShadowTreeCommitOptions& commitOptions) noexcept {
27+
TraceSection s(
28+
"AnimationBackendCommitHook::shadowTreeWillCommit",
29+
"surfaceId",
30+
shadowTree.getSurfaceId());
2631
if (commitOptions.source != ShadowTreeCommitSource::React &&
2732
commitOptions.source != ShadowTreeCommitSource::AnimationEndSync) {
2833
return newRootShadowNode;

0 commit comments

Comments
 (0)