perf: run ready VM quanta without per-quantum timer delays

This commit is contained in:
2026-10-24 02:27:51 +08:00
parent 1cf07a75f7
commit fa6dfa7062
+8 -2
View File
@@ -196,7 +196,10 @@ fn start_server_observed(
match worker.resume_request(&job, input, &worker_namespace, &worker_notify) { match worker.resume_request(&job, input, &worker_namespace, &worker_notify) {
RequestProgress::Pending(input) => { RequestProgress::Pending(input) => {
pending = Some((job, input)); pending = Some((job, input));
thread::sleep(std::time::Duration::from_millis(1)); // A soft VM quantum is a control boundary, not a
// minimum-duration time slice. Yield to other ready
// threads without charging a timer delay per quantum.
thread::yield_now();
} }
RequestProgress::Complete(response) => { RequestProgress::Complete(response) => {
let _ = job.request.respond(response); let _ = job.request.respond(response);
@@ -208,7 +211,7 @@ fn start_server_observed(
let wait = if worker.repl.as_ref().is_some_and(|(_, runtime)| { let wait = if worker.repl.as_ref().is_some_and(|(_, runtime)| {
runtime.has_pending_refresh() || runtime.has_cooperative_tasks() runtime.has_pending_refresh() || runtime.has_cooperative_tasks()
}) { }) {
std::time::Duration::from_millis(1) std::time::Duration::ZERO
} else { } else {
std::time::Duration::from_millis(100) std::time::Duration::from_millis(100)
}; };
@@ -239,6 +242,9 @@ fn start_server_observed(
}) { }) {
worker.repl = None; worker.repl = None;
} }
if wait.is_zero() {
thread::yield_now();
}
} }
} }
} }