Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactor in RuntimeScheduler_Modern to favor references over shared_ptr for non-owning function args #43852

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -10,8 +10,8 @@
#include <cxxreact/JSExecutor.h>
#include <cxxreact/ReactMarker.h>
#include <jsi/instrumentation.h>
#include <react/performance/timeline/PerformanceEntryReporter.h>
#include "NativePerformance.h"
#include "PerformanceEntryReporter.h"

#include "Plugins.h"

Expand All @@ -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 @@ -11,14 +11,7 @@
#include <memory>
#include <string>

#include "NativePerformanceObserver.h"

namespace facebook::react {
class PerformanceEntryReporter;

#pragma mark - Structs

#pragma mark - implementation

class NativePerformance : public NativePerformanceCxxSpec<NativePerformance> {
public:
Expand Down Expand Up @@ -54,8 +47,6 @@ class NativePerformance : public NativePerformanceCxxSpec<NativePerformance> {
// tracking.
std::unordered_map<std::string, double> getReactNativeStartupTiming(
jsi::Runtime& rt);

private:
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <memory>

#include "NativePerformanceObserver.h"
#include "PerformanceEntryReporter.h"

#include <react/performance/timeline/PerformanceEntryReporter.h>
#include <react/renderer/uimanager/UIManagerBinding.h>
#include <react/utils/CoreFeatures.h>

Expand All @@ -26,114 +26,97 @@ 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,
int32_t entryType) {
PerformanceEntryReporter& reporter = PerformanceEntryReporter::getInstance();

PerformanceEntryType entryTypeEnum =
static_cast<PerformanceEntryType>(entryType);
reporter.startReporting(entryTypeEnum);

if (entryTypeEnum == PerformanceEntryType::EVENT &&
CoreFeatures::enableReportEventPaintTime) {
UIManagerBinding::getBinding(rt)->getUIManager().registerMountHook(
reporter);
}
jsi::Runtime& /*rt*/,
PerformanceEntryType entryType) {
auto reporter = PerformanceEntryReporter::getInstance();

reporter->startReporting(entryType);
}

void NativePerformanceObserver::stopReporting(
jsi::Runtime& rt,
int32_t entryType) {
PerformanceEntryReporter& reporter = PerformanceEntryReporter::getInstance();

PerformanceEntryType entryTypeEnum =
static_cast<PerformanceEntryType>(entryType);
reporter.stopReporting(entryTypeEnum);

if (entryTypeEnum == PerformanceEntryType::EVENT &&
CoreFeatures::enableReportEventPaintTime) {
UIManagerBinding::getBinding(rt)->getUIManager().unregisterMountHook(
reporter);
}
jsi::Runtime& /*rt*/,
PerformanceEntryType entryType) {
auto reporter = PerformanceEntryReporter::getInstance();

reporter->stopReporting(entryType);
}

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

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

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

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

std::vector<std::pair<std::string, uint32_t>>
NativePerformanceObserver::getEventCounts(jsi::Runtime& rt) {
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());
}

void NativePerformanceObserver::setDurationThreshold(
jsi::Runtime& rt,
int32_t entryType,
jsi::Runtime& /*rt*/,
PerformanceEntryType entryType,
double durationThreshold) {
PerformanceEntryReporter::getInstance().setDurationThreshold(
static_cast<PerformanceEntryType>(entryType), durationThreshold);
PerformanceEntryReporter::getInstance()->setDurationThreshold(
entryType, durationThreshold);
}

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

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

std::vector<RawPerformanceEntryType>
NativePerformanceObserver::getSupportedPerformanceEntryTypes(jsi::Runtime& rt) {
std::vector<PerformanceEntryType>
NativePerformanceObserver::getSupportedPerformanceEntryTypes(
jsi::Runtime& /*rt*/) {
return {
static_cast<RawPerformanceEntryType>(PerformanceEntryType::MARK),
static_cast<RawPerformanceEntryType>(PerformanceEntryType::MEASURE),
static_cast<RawPerformanceEntryType>(PerformanceEntryType::EVENT),
PerformanceEntryType::MARK,
PerformanceEntryType::MEASURE,
PerformanceEntryType::EVENT,
};
}

Expand Down
Loading
Loading