Skip to content

Commit

Permalink
Systrace instrumentation for prop parsing (facebook#45153)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#45153

This diff adds more Systrace logging to the component create/update flow.
Changelog: [Internal]

Differential Revision: D56706472
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Jun 25, 2024
1 parent 4a8f0ee commit f5182f6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.facebook.react.uimanager.events.SynchronousEventReceiver;
import com.facebook.react.views.text.TextLayoutManager;
import com.facebook.systrace.Systrace;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -753,6 +754,7 @@ private void preallocateView(
@Nullable Object eventEmitterWrapper,
boolean isLayoutable) {

Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManager.preallocateView");
mMountItemDispatcher.addPreAllocateMountItem(
MountItemFactory.createPreAllocateViewMountItem(
rootTag,
Expand All @@ -762,6 +764,7 @@ private void preallocateView(
(StateWrapper) stateWrapper,
(EventEmitterWrapper) eventEmitterWrapper,
isLayoutable));
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <functional>
#include <memory>

#include <cxxreact/SystraceSection.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/core/ComponentDescriptor.h>
#include <react/renderer/core/EventDispatcher.h>
Expand Down Expand Up @@ -66,6 +67,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
std::shared_ptr<ShadowNode> createShadowNode(
const ShadowNodeFragment& fragment,
const ShadowNodeFamily::Shared& family) const override {
SystraceSection s("ConcreteComponentDescriptor::createShadowNode");
auto shadowNode =
std::make_shared<ShadowNodeT>(fragment, family, getTraits());

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

rawProps.parse(rawPropsParser_);

// Call old-style constructor
auto shadowNodeProps = ShadowNodeT::Props(context, rawProps, props);

// Use the new-style iterator
// Note that we just check if `Props` has this flag set, no matter
// the type of ShadowNode; it acts as the single global flag.
if (CoreFeatures::enablePropIteratorSetter) {
auto shadowNodeProps = ShadowNodeT::Props(context, rawProps, props);
rawProps.iterateOverValues([&](RawPropsPropNameHash hash,
const char* propName,
const RawValue& fn) {
shadowNodeProps.get()->setProp(context, hash, propName, fn);
});
return shadowNodeProps;
} else {
SystraceSection s2(
"ConcreteComponentDescriptor::cloneProps - old-style constructor");
// Call old-style constructor
return ShadowNodeT::Props(context, rawProps, props);
}

return shadowNodeProps;
};

virtual State::Shared createInitialState(
Expand Down Expand Up @@ -160,6 +165,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {

ShadowNodeFamily::Shared createFamily(
const ShadowNodeFamilyFragment& fragment) const override {
SystraceSection s("ConcreteComponentDescriptor::createFamily");
auto eventEmitter = std::make_shared<const ConcreteEventEmitter>(
std::make_shared<EventTarget>(fragment.instanceHandle),
eventDispatcher_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ConcreteShadowNode : public BaseShadowNodeT {
const PropsParserContext& context,
const RawProps& rawProps,
const Props::Shared& baseProps = nullptr) {
return std::make_shared<PropsT>(
return std::make_shared<PropsT>(
context,
baseProps ? static_cast<const PropsT&>(*baseProps)
: *defaultSharedProps(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "RawProps.h"

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

void RawProps::parse(const RawPropsParser& parser) noexcept {
SystraceSection s("RawProps::parse");
react_native_assert(parser_ == nullptr && "A parser was already assigned.");
parser_ = &parser;
parser.preparse(*this);
Expand All @@ -172,6 +174,7 @@ void RawProps::parse(const RawPropsParser& parser) noexcept {
* will be removed as soon Android implementation does not need it.
*/
RawProps::operator folly::dynamic() const noexcept {
SystraceSection s("RawProps::operator folly::dynamic()");
switch (mode_) {
case Mode::Empty:
return folly::dynamic::object();
Expand Down Expand Up @@ -212,6 +215,7 @@ const RawValue* RawProps::at(
void RawProps::iterateOverValues(
const std::function<
void(RawPropsPropNameHash, const char*, const RawValue&)>& fn) const {
SystraceSection s("RawProps::iterateOverValues");
return parser_->iterateOverValues(*this, fn);
}

Expand Down

0 comments on commit f5182f6

Please sign in to comment.