mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Systrace instrumentation for prop parsing (#45153)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45153 This diff adds more Systrace logging to the component create/update flow. Changelog: [Internal] Reviewed By: javache Differential Revision: D56706472 fbshipit-source-id: c94445693694dfee43f1d46881fc1e18a507eb5e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c5653a03fb
commit
5532e511af
+13
-5
@@ -8,7 +8,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <cxxreact/SystraceSection.h>
|
||||
#include <react/debug/react_native_assert.h>
|
||||
#include <react/renderer/core/ComponentDescriptor.h>
|
||||
#include <react/renderer/core/EventDispatcher.h>
|
||||
@@ -65,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());
|
||||
|
||||
@@ -96,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
|
||||
@@ -111,18 +115,18 @@ 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);
|
||||
#ifdef ANDROID
|
||||
const auto& dynamic = shadowNodeProps->rawProps;
|
||||
#else
|
||||
const auto& dynamic = static_cast<folly::dynamic>(rawProps);
|
||||
#endif
|
||||
SystraceSection s2(
|
||||
"ConcreteComponentDescriptor::cloneProps - iterateOverValues");
|
||||
for (const auto& pair : dynamic.items()) {
|
||||
const auto& name = pair.first.getString();
|
||||
shadowNodeProps->setProp(
|
||||
@@ -131,9 +135,13 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
|
||||
name.c_str(),
|
||||
RawValue(pair.second));
|
||||
}
|
||||
return shadowNodeProps;
|
||||
} else {
|
||||
SystraceSection s3(
|
||||
"ConcreteComponentDescriptor::cloneProps - old-style constructor");
|
||||
// Call old-style constructor
|
||||
return ShadowNodeT::Props(context, rawProps, props);
|
||||
}
|
||||
|
||||
return shadowNodeProps;
|
||||
};
|
||||
|
||||
virtual State::Shared createInitialState(
|
||||
|
||||
@@ -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>
|
||||
@@ -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);
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user