Skip to content

Commit

Permalink
Decouple event logger from PerformanceEntryReporter and remove single…
Browse files Browse the repository at this point in the history
…ton (facebook#43853)

Summary:
Pull Request resolved: facebook#43853

Changelog: [internal]

## Context

This is part of a refactor to decouple the performance entry reporter from the rendering infra and from the native module that uses it.

## Changes

This moves the logic to report the timing of events to a separate class (outside `PerformanceEntryReporter` that now is agnostic to the rendering infra).

Reviewed By: sammy-SC

Differential Revision: D55646392
  • Loading branch information
rubennorte authored and facebook-github-bot committed Apr 9, 2024
1 parent 973bf00 commit 9aba8a9
Show file tree
Hide file tree
Showing 26 changed files with 565 additions and 384 deletions.
1 change: 1 addition & 0 deletions packages/react-native/React/React-RCTFabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Pod::Spec.new do |s|
add_dependency(s, "React-featureflags")
add_dependency(s, "React-debug")
add_dependency(s, "React-utils")
add_dependency(s, "React-performancetimeline")
add_dependency(s, "React-rendererdebug")
add_dependency(s, "React-rendererconsistency")
add_dependency(s, "React-runtimescheduler")
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ android {
"react_codegen_rncore",
"react_debug",
"react_featureflags",
"react_performance_timeline",
"react_utils",
"react_render_componentregistry",
"react_newarchdefaults",
Expand All @@ -565,6 +566,7 @@ android {
"react_render_consistency",
"react_render_dom",
"react_render_graphics",
"react_render_observers_events",
"rrc_image",
"rrc_root",
"rrc_view",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ add_react_common_subdir(react/renderer/runtimescheduler)
add_react_common_subdir(react/debug)
add_react_common_subdir(react/config)
add_react_common_subdir(react/featureflags)
add_react_common_subdir(react/performance/timeline)
add_react_common_subdir(react/renderer/animations)
add_react_common_subdir(react/renderer/attributedstring)
add_react_common_subdir(react/renderer/componentregistry)
Expand Down Expand Up @@ -99,6 +100,7 @@ add_react_common_subdir(react/renderer/components/unimplementedview)
add_react_common_subdir(react/renderer/components/modal)
add_react_common_subdir(react/renderer/components/scrollview)
add_react_common_subdir(react/renderer/leakchecker)
add_react_common_subdir(react/renderer/observers/events)
add_react_common_subdir(react/renderer/textlayoutmanager)
add_react_common_subdir(react/utils)
add_react_common_subdir(react/bridging)
Expand Down
13 changes: 13 additions & 0 deletions packages/react-native/ReactCommon/React-Fabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,24 @@ Pod::Spec.new do |s|
ss.header_dir = "react/renderer/mounting"
end

s.subspec "observers" do |ss|
ss.subspec "events" do |sss|
sss.dependency folly_dep_name, folly_version
sss.compiler_flags = folly_compiler_flags
sss.source_files = "react/renderer/observers/events/**/*.{m,mm,cpp,h}"
sss.exclude_files = "react/renderer/observers/events/tests"
sss.header_dir = "react/renderer/observers/events"
end
end

s.subspec "scheduler" do |ss|
ss.dependency folly_dep_name, folly_version
ss.compiler_flags = folly_compiler_flags
ss.source_files = "react/renderer/scheduler/**/*.{m,mm,cpp,h}"
ss.header_dir = "react/renderer/scheduler"

ss.dependency "React-performancetimeline"
ss.dependency "React-Fabric/observers/events"
end

s.subspec "templateprocessor" do |ss|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void NativePerformance::mark(
jsi::Runtime& rt,
std::string name,
double startTime) {
PerformanceEntryReporter::getInstance().mark(name, startTime);
PerformanceEntryReporter::getInstance()->mark(name, startTime);
}

void NativePerformance::measure(
Expand All @@ -45,7 +45,7 @@ void NativePerformance::measure(
std::optional<double> duration,
std::optional<std::string> startMark,
std::optional<std::string> endMark) {
PerformanceEntryReporter::getInstance().measure(
PerformanceEntryReporter::getInstance()->measure(
name, startTime, endTime, duration, startMark, endMark);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,80 +26,62 @@ namespace facebook::react {

NativePerformanceObserver::NativePerformanceObserver(
std::shared_ptr<CallInvoker> jsInvoker)
: NativePerformanceObserverCxxSpec(std::move(jsInvoker)) {
setEventLogger(&PerformanceEntryReporter::getInstance());
}

NativePerformanceObserver::~NativePerformanceObserver() {
setEventLogger(nullptr);
}
: NativePerformanceObserverCxxSpec(std::move(jsInvoker)) {}

void NativePerformanceObserver::startReporting(
jsi::Runtime& rt,
jsi::Runtime& /*rt*/,
PerformanceEntryType entryType) {
PerformanceEntryReporter& reporter = PerformanceEntryReporter::getInstance();

reporter.startReporting(entryType);
auto reporter = PerformanceEntryReporter::getInstance();

if (entryType == PerformanceEntryType::EVENT &&
CoreFeatures::enableReportEventPaintTime) {
UIManagerBinding::getBinding(rt)->getUIManager().registerMountHook(
reporter);
}
reporter->startReporting(entryType);
}

void NativePerformanceObserver::stopReporting(
jsi::Runtime& rt,
jsi::Runtime& /*rt*/,
PerformanceEntryType entryType) {
PerformanceEntryReporter& reporter = PerformanceEntryReporter::getInstance();
auto reporter = PerformanceEntryReporter::getInstance();

reporter.stopReporting(entryType);

if (entryType == PerformanceEntryType::EVENT &&
CoreFeatures::enableReportEventPaintTime) {
UIManagerBinding::getBinding(rt)->getUIManager().unregisterMountHook(
reporter);
}
reporter->stopReporting(entryType);
}

void NativePerformanceObserver::setIsBuffered(
jsi::Runtime& /*rt*/,
const std::vector<PerformanceEntryType> entryTypes,
bool isBuffered) {
for (const PerformanceEntryType entryType : entryTypes) {
PerformanceEntryReporter::getInstance().setAlwaysLogged(
PerformanceEntryReporter::getInstance()->setAlwaysLogged(
entryType, isBuffered);
}
}

PerformanceEntryReporter::PopPendingEntriesResult
NativePerformanceObserver::popPendingEntries(jsi::Runtime& /*rt*/) {
return PerformanceEntryReporter::getInstance().popPendingEntries();
return PerformanceEntryReporter::getInstance()->popPendingEntries();
}

void NativePerformanceObserver::setOnPerformanceEntryCallback(
jsi::Runtime& /*rt*/,
std::optional<AsyncCallback<>> callback) {
if (callback) {
PerformanceEntryReporter::getInstance().setReportingCallback(
PerformanceEntryReporter::getInstance()->setReportingCallback(
[callback = std::move(callback)]() {
callback->callWithPriority(SchedulerPriority::IdlePriority);
});
} else {
PerformanceEntryReporter::getInstance().setReportingCallback(nullptr);
PerformanceEntryReporter::getInstance()->setReportingCallback(nullptr);
}
}

void NativePerformanceObserver::logRawEntry(
jsi::Runtime& /*rt*/,
const PerformanceEntry entry) {
PerformanceEntryReporter::getInstance().logEntry(entry);
PerformanceEntryReporter::getInstance()->logEntry(entry);
}

std::vector<std::pair<std::string, uint32_t>>
NativePerformanceObserver::getEventCounts(jsi::Runtime& /*rt*/) {
const auto& eventCounts =
PerformanceEntryReporter::getInstance().getEventCounts();
PerformanceEntryReporter::getInstance()->getEventCounts();
return std::vector<std::pair<std::string, uint32_t>>(
eventCounts.begin(), eventCounts.end());
}
Expand All @@ -108,23 +90,23 @@ void NativePerformanceObserver::setDurationThreshold(
jsi::Runtime& /*rt*/,
PerformanceEntryType entryType,
double durationThreshold) {
PerformanceEntryReporter::getInstance().setDurationThreshold(
PerformanceEntryReporter::getInstance()->setDurationThreshold(
entryType, durationThreshold);
}

void NativePerformanceObserver::clearEntries(
jsi::Runtime& /*rt*/,
PerformanceEntryType entryType,
std::optional<std::string> entryName) {
PerformanceEntryReporter::getInstance().clearEntries(
PerformanceEntryReporter::getInstance()->clearEntries(
entryType, entryName ? entryName->c_str() : std::string_view{});
}

std::vector<PerformanceEntry> NativePerformanceObserver::getEntries(
jsi::Runtime& /*rt*/,
std::optional<PerformanceEntryType> entryType,
std::optional<std::string> entryName) {
return PerformanceEntryReporter::getInstance().getEntries(
return PerformanceEntryReporter::getInstance()->getEntries(
entryType, entryName ? entryName->c_str() : std::string_view{});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class NativePerformanceObserver
: public NativePerformanceObserverCxxSpec<NativePerformanceObserver> {
public:
NativePerformanceObserver(std::shared_ptr<CallInvoker> jsInvoker);
~NativePerformanceObserver();

void startReporting(jsi::Runtime& rt, PerformanceEntryType entryType);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(
-fexceptions
-frtti
-std=c++20
-Wall
-Wpedantic
-DLOG_TAG=\"ReactNative\")

file(GLOB react_performance_timeline_SRC CONFIGURE_DEPENDS *.cpp)
add_library(react_performance_timeline SHARED ${react_performance_timeline_SRC})

target_include_directories(react_performance_timeline PUBLIC ${REACT_COMMON_DIR})
target_link_libraries(react_performance_timeline
react_cxxreact)
Loading

0 comments on commit 9aba8a9

Please sign in to comment.