Skip to content

Commit f5182f6

Browse files
dmytrorykunfacebook-github-bot
authored andcommitted
Systrace instrumentation for prop parsing (facebook#45153)
Summary: Pull Request resolved: facebook#45153 This diff adds more Systrace logging to the component create/update flow. Changelog: [Internal] Differential Revision: D56706472
1 parent 4a8f0ee commit f5182f6

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
import com.facebook.react.uimanager.events.RCTEventEmitter;
8787
import com.facebook.react.uimanager.events.SynchronousEventReceiver;
8888
import com.facebook.react.views.text.TextLayoutManager;
89+
import com.facebook.systrace.Systrace;
8990
import java.util.ArrayList;
9091
import java.util.HashMap;
9192
import java.util.HashSet;
@@ -753,6 +754,7 @@ private void preallocateView(
753754
@Nullable Object eventEmitterWrapper,
754755
boolean isLayoutable) {
755756

757+
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManager.preallocateView");
756758
mMountItemDispatcher.addPreAllocateMountItem(
757759
MountItemFactory.createPreAllocateViewMountItem(
758760
rootTag,
@@ -762,6 +764,7 @@ private void preallocateView(
762764
(StateWrapper) stateWrapper,
763765
(EventEmitterWrapper) eventEmitterWrapper,
764766
isLayoutable));
767+
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
765768
}
766769

767770
@SuppressWarnings("unused")

packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <functional>
1111
#include <memory>
1212

13+
#include <cxxreact/SystraceSection.h>
1314
#include <react/debug/react_native_assert.h>
1415
#include <react/renderer/core/ComponentDescriptor.h>
1516
#include <react/renderer/core/EventDispatcher.h>
@@ -66,6 +67,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
6667
std::shared_ptr<ShadowNode> createShadowNode(
6768
const ShadowNodeFragment& fragment,
6869
const ShadowNodeFamily::Shared& family) const override {
70+
SystraceSection s("ConcreteComponentDescriptor::createShadowNode");
6971
auto shadowNode =
7072
std::make_shared<ShadowNodeT>(fragment, family, getTraits());
7173

@@ -97,6 +99,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
9799
const PropsParserContext& context,
98100
const Props::Shared& props,
99101
RawProps rawProps) const override {
102+
SystraceSection s1("ConcreteComponentDescriptor::cloneProps");
100103
// Optimization:
101104
// Quite often nodes are constructed with default/empty props: the base
102105
// `props` object is `null` (there no base because it's not cloning) and the
@@ -112,21 +115,23 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
112115

113116
rawProps.parse(rawPropsParser_);
114117

115-
// Call old-style constructor
116-
auto shadowNodeProps = ShadowNodeT::Props(context, rawProps, props);
117-
118118
// Use the new-style iterator
119119
// Note that we just check if `Props` has this flag set, no matter
120120
// the type of ShadowNode; it acts as the single global flag.
121121
if (CoreFeatures::enablePropIteratorSetter) {
122+
auto shadowNodeProps = ShadowNodeT::Props(context, rawProps, props);
122123
rawProps.iterateOverValues([&](RawPropsPropNameHash hash,
123124
const char* propName,
124125
const RawValue& fn) {
125126
shadowNodeProps.get()->setProp(context, hash, propName, fn);
126127
});
128+
return shadowNodeProps;
129+
} else {
130+
SystraceSection s2(
131+
"ConcreteComponentDescriptor::cloneProps - old-style constructor");
132+
// Call old-style constructor
133+
return ShadowNodeT::Props(context, rawProps, props);
127134
}
128-
129-
return shadowNodeProps;
130135
};
131136

132137
virtual State::Shared createInitialState(
@@ -160,6 +165,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
160165

161166
ShadowNodeFamily::Shared createFamily(
162167
const ShadowNodeFamilyFragment& fragment) const override {
168+
SystraceSection s("ConcreteComponentDescriptor::createFamily");
163169
auto eventEmitter = std::make_shared<const ConcreteEventEmitter>(
164170
std::make_shared<EventTarget>(fragment.instanceHandle),
165171
eventDispatcher_);

packages/react-native/ReactCommon/react/renderer/core/ConcreteShadowNode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ConcreteShadowNode : public BaseShadowNodeT {
7575
const PropsParserContext& context,
7676
const RawProps& rawProps,
7777
const Props::Shared& baseProps = nullptr) {
78-
return std::make_shared<PropsT>(
78+
return std::make_shared<PropsT>(
7979
context,
8080
baseProps ? static_cast<const PropsT&>(*baseProps)
8181
: *defaultSharedProps(),

packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "RawProps.h"
99

10+
#include <cxxreact/SystraceSection.h>
1011
#include <react/debug/react_native_assert.h>
1112
#include <react/renderer/core/RawPropsKey.h>
1213
#include <react/renderer/core/RawPropsParser.h>
@@ -161,6 +162,7 @@ RawProps& RawProps::operator=(const RawProps& other) noexcept {
161162
}
162163

163164
void RawProps::parse(const RawPropsParser& parser) noexcept {
165+
SystraceSection s("RawProps::parse");
164166
react_native_assert(parser_ == nullptr && "A parser was already assigned.");
165167
parser_ = &parser;
166168
parser.preparse(*this);
@@ -172,6 +174,7 @@ void RawProps::parse(const RawPropsParser& parser) noexcept {
172174
* will be removed as soon Android implementation does not need it.
173175
*/
174176
RawProps::operator folly::dynamic() const noexcept {
177+
SystraceSection s("RawProps::operator folly::dynamic()");
175178
switch (mode_) {
176179
case Mode::Empty:
177180
return folly::dynamic::object();
@@ -212,6 +215,7 @@ const RawValue* RawProps::at(
212215
void RawProps::iterateOverValues(
213216
const std::function<
214217
void(RawPropsPropNameHash, const char*, const RawValue&)>& fn) const {
218+
SystraceSection s("RawProps::iterateOverValues");
215219
return parser_->iterateOverValues(*this, fn);
216220
}
217221

0 commit comments

Comments
 (0)