diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp index 2c4e45e4c28139..1b6f9379d1cb75 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.cpp @@ -10,8 +10,8 @@ #include #include #include +#include #include "NativePerformance.h" -#include "PerformanceEntryReporter.h" #include "Plugins.h" diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.h b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.h index 65c1ef07e02fab..1c95d80abd4118 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.h +++ b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformance.h @@ -11,14 +11,7 @@ #include #include -#include "NativePerformanceObserver.h" - namespace facebook::react { -class PerformanceEntryReporter; - -#pragma mark - Structs - -#pragma mark - implementation class NativePerformance : public NativePerformanceCxxSpec { public: @@ -54,8 +47,6 @@ class NativePerformance : public NativePerformanceCxxSpec { // tracking. std::unordered_map getReactNativeStartupTiming( jsi::Runtime& rt); - - private: }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp index 5bd4e8f2aac4ba..ca5bbbfe076d1e 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.cpp @@ -8,8 +8,8 @@ #include #include "NativePerformanceObserver.h" -#include "PerformanceEntryReporter.h" +#include #include #include @@ -80,7 +80,14 @@ NativePerformanceObserver::popPendingEntries(jsi::Runtime& /*rt*/) { void NativePerformanceObserver::setOnPerformanceEntryCallback( jsi::Runtime& /*rt*/, std::optional> 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( diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.h b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.h index 8980908bb4e0d5..9ef3506695e733 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.h +++ b/packages/react-native/ReactCommon/react/nativemodule/webperformance/NativePerformanceObserver.h @@ -8,11 +8,11 @@ #pragma once #include +#include #include #include #include #include -#include "PerformanceEntryReporter.h" namespace facebook::react { diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/BoundedConsumableBuffer.h b/packages/react-native/ReactCommon/react/performance/timeline/BoundedConsumableBuffer.h similarity index 100% rename from packages/react-native/ReactCommon/react/nativemodule/webperformance/BoundedConsumableBuffer.h rename to packages/react-native/ReactCommon/react/performance/timeline/BoundedConsumableBuffer.h diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/PerformanceEntryReporter.cpp b/packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.cpp similarity index 99% rename from packages/react-native/ReactCommon/react/nativemodule/webperformance/PerformanceEntryReporter.cpp rename to packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.cpp index 60669bde4d188e..756877d17e0860 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/webperformance/PerformanceEntryReporter.cpp +++ b/packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.cpp @@ -30,8 +30,8 @@ PerformanceEntryReporter::PerformanceEntryReporter() { } void PerformanceEntryReporter::setReportingCallback( - std::optional> callback) { - callback_ = callback; + std::function callback) { + callback_ = std::move(callback); } DOMHighResTimeStamp PerformanceEntryReporter::getCurrentTimeStamp() const { @@ -295,7 +295,7 @@ void PerformanceEntryReporter::logEventEntry( void PerformanceEntryReporter::scheduleFlushBuffer() { if (callback_) { - callback_->callWithPriority(SchedulerPriority::IdlePriority); + callback_(); } } diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/PerformanceEntryReporter.h b/packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.h similarity index 97% rename from packages/react-native/ReactCommon/react/nativemodule/webperformance/PerformanceEntryReporter.h rename to packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.h index 287d05bdf6a2d7..13443c29d2b2d6 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/webperformance/PerformanceEntryReporter.h +++ b/packages/react-native/ReactCommon/react/performance/timeline/PerformanceEntryReporter.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include #include @@ -99,7 +98,7 @@ class PerformanceEntryReporter : public EventLogger, public UIManagerMountHook { uint32_t droppedEntriesCount; }; - void setReportingCallback(std::optional> callback); + void setReportingCallback(std::function callback); void startReporting(PerformanceEntryType entryType); void stopReporting(PerformanceEntryType entryType); void stopReporting(); @@ -174,11 +173,11 @@ class PerformanceEntryReporter : public EventLogger, public UIManagerMountHook { } void setTimeStampProvider(std::function provider) { - timeStampProvider_ = provider; + timeStampProvider_ = std::move(provider); } private: - std::optional> callback_; + std::function callback_; mutable std::mutex entriesMutex_; std::array buffers_; diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/tests/BoundedConsumableBufferTest.cpp b/packages/react-native/ReactCommon/react/performance/timeline/tests/BoundedConsumableBufferTest.cpp similarity index 100% rename from packages/react-native/ReactCommon/react/nativemodule/webperformance/tests/BoundedConsumableBufferTest.cpp rename to packages/react-native/ReactCommon/react/performance/timeline/tests/BoundedConsumableBufferTest.cpp diff --git a/packages/react-native/ReactCommon/react/nativemodule/webperformance/tests/PerformanceEntryReporterTest.cpp b/packages/react-native/ReactCommon/react/performance/timeline/tests/PerformanceEntryReporterTest.cpp similarity index 100% rename from packages/react-native/ReactCommon/react/nativemodule/webperformance/tests/PerformanceEntryReporterTest.cpp rename to packages/react-native/ReactCommon/react/performance/timeline/tests/PerformanceEntryReporterTest.cpp