Skip to content

Commit e0f6066

Browse files
rubennortefacebook-github-bot
authored andcommitted
Clean up old and unused implementation of microtasks (#40870)
Summary: 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
1 parent c9d0a00 commit e0f6066

File tree

2 files changed

+0
-55
lines changed

2 files changed

+0
-55
lines changed

packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -208,30 +208,6 @@ void JSIExecutor::registerBundle(
208208
ReactMarker::REGISTER_JS_SEGMENT_STOP, tag.c_str());
209209
}
210210

211-
// Looping on \c drainMicrotasks until it completes or hits the retries bound.
212-
static void performMicrotaskCheckpoint(jsi::Runtime& runtime) {
213-
uint8_t retries = 0;
214-
// A heuristic number to guard infinite or absurd numbers of retries.
215-
const static unsigned int kRetriesBound = 255;
216-
217-
while (retries < kRetriesBound) {
218-
try {
219-
// The default behavior of \c drainMicrotasks is unbounded execution.
220-
// We may want to make it bounded in the future.
221-
if (runtime.drainMicrotasks()) {
222-
break;
223-
}
224-
} catch (jsi::JSError& error) {
225-
handleJSError(runtime, error, true);
226-
}
227-
retries++;
228-
}
229-
230-
if (retries == kRetriesBound) {
231-
throw std::runtime_error("Hits microtasks retries bound.");
232-
}
233-
}
234-
235211
void JSIExecutor::callFunction(
236212
const std::string& moduleId,
237213
const std::string& methodId,
@@ -267,8 +243,6 @@ void JSIExecutor::callFunction(
267243
std::runtime_error("Error calling " + moduleId + "." + methodId));
268244
}
269245

270-
performMicrotaskCheckpoint(*runtime_);
271-
272246
callNativeModules(ret, true);
273247
}
274248

@@ -288,8 +262,6 @@ void JSIExecutor::invokeCallback(
288262
folly::to<std::string>("Error invoking callback ", callbackId)));
289263
}
290264

291-
performMicrotaskCheckpoint(*runtime_);
292-
293265
callNativeModules(ret, true);
294266
}
295267

@@ -426,7 +398,6 @@ void JSIExecutor::flush() {
426398
SystraceSection s("JSIExecutor::flush");
427399
if (flushedQueue_) {
428400
Value ret = flushedQueue_->call(*runtime_);
429-
performMicrotaskCheckpoint(*runtime_);
430401
callNativeModules(ret, true);
431402
return;
432403
}
@@ -444,7 +415,6 @@ void JSIExecutor::flush() {
444415
// get the pending queue of native calls.
445416
bindBridge();
446417
Value ret = flushedQueue_->call(*runtime_);
447-
performMicrotaskCheckpoint(*runtime_);
448418
callNativeModules(ret, true);
449419
} else if (delegate_) {
450420
// If we have a delegate, we need to call it; we pass a null list to

packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,6 @@
2424

2525
namespace facebook::react {
2626

27-
// Looping on \c drainMicrotasks until it completes or hits the retries bound.
28-
static void performMicrotaskCheckpoint(jsi::Runtime& runtime) {
29-
uint8_t retries = 0;
30-
// A heuristic number to guard inifinite or absurd numbers of retries.
31-
constexpr unsigned int kRetriesBound = 255;
32-
33-
while (retries < kRetriesBound) {
34-
try {
35-
// The default behavior of \c drainMicrotasks is unbounded execution.
36-
// We may want to make it bounded in the future.
37-
if (runtime.drainMicrotasks()) {
38-
break;
39-
}
40-
} catch (jsi::JSError& error) {
41-
handleJSError(runtime, error, true);
42-
}
43-
retries++;
44-
}
45-
46-
if (retries == kRetriesBound) {
47-
throw std::runtime_error("Hits microtasks retries bound.");
48-
}
49-
}
50-
5127
ReactInstance::ReactInstance(
5228
std::unique_ptr<jsi::Runtime> runtime,
5329
std::shared_ptr<MessageQueueThread> jsMessageQueueThread,
@@ -91,7 +67,6 @@ ReactInstance::ReactInstance(
9167
if (auto strongTimerManager = weakTimerManager.lock()) {
9268
strongTimerManager->callReactNativeMicrotasks(*strongRuntime);
9369
}
94-
performMicrotaskCheckpoint(*strongRuntime);
9570
} catch (jsi::JSError& originalError) {
9671
handleJSError(*strongRuntime, originalError, true);
9772
}

0 commit comments

Comments
 (0)