1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

perf(core): immediately schedule another tick if there are unpolled ops (#18611)

Currently we are "waking up" the runtime if at the end of the event loop
tick there are ops that haven't been polled. Waking up incurs a syscall
and it appears we can do another tick of the event loop, without
going through the "wake up" machinery.
This commit is contained in:
Bartek Iwańczuk 2023-04-14 12:55:47 +02:00 committed by GitHub
parent cb2ca234bb
commit 4317055a3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1182,6 +1182,7 @@ impl JsRuntime {
state.waker.register(cx.waker()); state.waker.register(cx.waker());
} }
loop {
if has_inspector { if has_inspector {
// We poll the inspector first. // We poll the inspector first.
let _ = self.inspector().borrow_mut().poll_unpin(cx); let _ = self.inspector().borrow_mut().poll_unpin(cx);
@ -1241,7 +1242,8 @@ impl JsRuntime {
if has_inspector { if has_inspector {
let inspector = self.inspector(); let inspector = self.inspector();
let has_active_sessions = inspector.borrow().has_active_sessions(); let has_active_sessions = inspector.borrow().has_active_sessions();
let has_blocking_sessions = inspector.borrow().has_blocking_sessions(); let has_blocking_sessions =
inspector.borrow().has_blocking_sessions();
if wait_for_inspector && has_active_sessions { if wait_for_inspector && has_active_sessions {
// If there are no blocking sessions (eg. REPL) we can now notify // If there are no blocking sessions (eg. REPL) we can now notify
@ -1263,15 +1265,18 @@ impl JsRuntime {
let state = self.state.borrow(); let state = self.state.borrow();
// Check if more async ops have been dispatched // Check if more async ops have been dispatched during this turn of
// during this turn of event loop. // event loop. In such case immediately do another turn of the event loop.
if state.have_unpolled_ops {
continue;
}
// If there are any pending background tasks, we also wake the runtime to // If there are any pending background tasks, we also wake the runtime to
// make sure we don't miss them. // make sure we don't miss them.
// TODO(andreubotella) The event loop will spin as long as there are pending // TODO(andreubotella) The event loop will spin as long as there are pending
// background tasks. We should look into having V8 notify us when a // background tasks. We should look into having V8 notify us when a
// background task is done. // background task is done.
if state.have_unpolled_ops if pending_state.has_pending_background_tasks
|| pending_state.has_pending_background_tasks
|| pending_state.has_tick_scheduled || pending_state.has_tick_scheduled
|| maybe_scheduling || maybe_scheduling
{ {
@ -1330,7 +1335,8 @@ impl JsRuntime {
state.waker.wake(); state.waker.wake();
} }
} }
break;
}
Poll::Pending Poll::Pending
} }