From 29bbab5a5a160411424c8ac13cc5ba5e65caaf28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Wed, 18 Oct 2023 06:14:25 -0700 Subject: [PATCH] Clean up old and unused implementation of microtasks (#40870) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/40870 This removes an old experiment to implement microtasks in React Native (which is incorrect now that the runtime scheduler executes multiple tasks per runtime executor "task"). `drainMicrotasks` is a no-op at the moment in Hermes because the flag isn't set, so this code is essentially dead. We'll add the new iteration of microtasks in a following PR. Changelog: [internal] Reviewed By: christophpurrer Differential Revision: D49536251 fbshipit-source-id: b8efba2d0310b9e33e65b79c60ad2db1c8109def --- .../jsiexecutor/jsireact/JSIExecutor.cpp | 30 ------------------- .../react/runtime/ReactInstance.cpp | 25 ---------------- 2 files changed, 55 deletions(-) diff --git a/packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp b/packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp index 279e45a056..51fabddc8f 100644 --- a/packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp +++ b/packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp @@ -208,30 +208,6 @@ void JSIExecutor::registerBundle( ReactMarker::REGISTER_JS_SEGMENT_STOP, tag.c_str()); } -// Looping on \c drainMicrotasks until it completes or hits the retries bound. -static void performMicrotaskCheckpoint(jsi::Runtime& runtime) { - uint8_t retries = 0; - // A heuristic number to guard infinite or absurd numbers of retries. - const static unsigned int kRetriesBound = 255; - - while (retries < kRetriesBound) { - try { - // The default behavior of \c drainMicrotasks is unbounded execution. - // We may want to make it bounded in the future. - if (runtime.drainMicrotasks()) { - break; - } - } catch (jsi::JSError& error) { - handleJSError(runtime, error, true); - } - retries++; - } - - if (retries == kRetriesBound) { - throw std::runtime_error("Hits microtasks retries bound."); - } -} - void JSIExecutor::callFunction( const std::string& moduleId, const std::string& methodId, @@ -267,8 +243,6 @@ void JSIExecutor::callFunction( std::runtime_error("Error calling " + moduleId + "." + methodId)); } - performMicrotaskCheckpoint(*runtime_); - callNativeModules(ret, true); } @@ -288,8 +262,6 @@ void JSIExecutor::invokeCallback( folly::to("Error invoking callback ", callbackId))); } - performMicrotaskCheckpoint(*runtime_); - callNativeModules(ret, true); } @@ -426,7 +398,6 @@ void JSIExecutor::flush() { SystraceSection s("JSIExecutor::flush"); if (flushedQueue_) { Value ret = flushedQueue_->call(*runtime_); - performMicrotaskCheckpoint(*runtime_); callNativeModules(ret, true); return; } @@ -444,7 +415,6 @@ void JSIExecutor::flush() { // get the pending queue of native calls. bindBridge(); Value ret = flushedQueue_->call(*runtime_); - performMicrotaskCheckpoint(*runtime_); callNativeModules(ret, true); } else if (delegate_) { // If we have a delegate, we need to call it; we pass a null list to diff --git a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp index 0f85cf0b72..abfda3b74a 100644 --- a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp +++ b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp @@ -24,30 +24,6 @@ namespace facebook::react { -// Looping on \c drainMicrotasks until it completes or hits the retries bound. -static void performMicrotaskCheckpoint(jsi::Runtime& runtime) { - uint8_t retries = 0; - // A heuristic number to guard inifinite or absurd numbers of retries. - constexpr unsigned int kRetriesBound = 255; - - while (retries < kRetriesBound) { - try { - // The default behavior of \c drainMicrotasks is unbounded execution. - // We may want to make it bounded in the future. - if (runtime.drainMicrotasks()) { - break; - } - } catch (jsi::JSError& error) { - handleJSError(runtime, error, true); - } - retries++; - } - - if (retries == kRetriesBound) { - throw std::runtime_error("Hits microtasks retries bound."); - } -} - ReactInstance::ReactInstance( std::unique_ptr runtime, std::shared_ptr jsMessageQueueThread, @@ -91,7 +67,6 @@ ReactInstance::ReactInstance( if (auto strongTimerManager = weakTimerManager.lock()) { strongTimerManager->callReactNativeMicrotasks(*strongRuntime); } - performMicrotaskCheckpoint(*strongRuntime); } catch (jsi::JSError& originalError) { handleJSError(*strongRuntime, originalError, true); }