From fa6dfa7062a18367a9b880c9d4b22d037e44a0a3 Mon Sep 17 00:00:00 2001 From: Codex Bot Date: Sat, 24 Oct 2026 02:27:51 +0800 Subject: [PATCH] perf: run ready VM quanta without per-quantum timer delays --- src/api.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/api.rs b/src/api.rs index a26370d..b613c70 100644 --- a/src/api.rs +++ b/src/api.rs @@ -196,7 +196,10 @@ fn start_server_observed( match worker.resume_request(&job, input, &worker_namespace, &worker_notify) { RequestProgress::Pending(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) => { let _ = job.request.respond(response); @@ -208,7 +211,7 @@ fn start_server_observed( let wait = if worker.repl.as_ref().is_some_and(|(_, runtime)| { runtime.has_pending_refresh() || runtime.has_cooperative_tasks() }) { - std::time::Duration::from_millis(1) + std::time::Duration::ZERO } else { std::time::Duration::from_millis(100) }; @@ -239,6 +242,9 @@ fn start_server_observed( }) { worker.repl = None; } + if wait.is_zero() { + thread::yield_now(); + } } } }