From 69f57ec19964a09a5de3a56b6fe3ee58bc7f39da Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Fri, 28 Jun 2024 04:08:16 -0700 Subject: [PATCH] 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 --- .../core/ConcreteComponentDescriptor.h | 18 +++++++++++++----- .../react/renderer/core/RawProps.cpp | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h index b7a4e0bdd0c8dc..d7fa46d5e72e75 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h @@ -8,7 +8,9 @@ #pragma once #include +#include +#include #include #include #include @@ -65,6 +67,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { std::shared_ptr createShadowNode( const ShadowNodeFragment& fragment, const ShadowNodeFamily::Shared& family) const override { + SystraceSection s("ConcreteComponentDescriptor::createShadowNode"); auto shadowNode = std::make_shared(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(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( diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp b/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp index 49f288e358d878..3eeffa3f9f4f0a 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp @@ -7,6 +7,7 @@ #include "RawProps.h" +#include #include #include #include @@ -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();