perf: wake promptly while cooperative source tasks remain runnable
Verify Tessera GUI / verify (push) Failing after 9m31s
Verify Tessera GUI / verify (push) Failing after 9m31s
This commit is contained in:
+3
-5
@@ -107,11 +107,9 @@ fn start_server_observed(
|
||||
continue;
|
||||
}
|
||||
worker.refresh_viewport(&worker_namespace, &worker_notify);
|
||||
let wait = if worker
|
||||
.repl
|
||||
.as_ref()
|
||||
.is_some_and(|(_, runtime)| runtime.has_pending_refresh())
|
||||
{
|
||||
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)
|
||||
} else {
|
||||
std::time::Duration::from_millis(100)
|
||||
|
||||
@@ -555,6 +555,10 @@ impl ReplSession {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn has_cooperative_tasks(&self) -> bool {
|
||||
self.bridge.has_cooperative_tasks()
|
||||
}
|
||||
|
||||
pub fn has_pending_refresh(&self) -> bool {
|
||||
self.refresh.is_some()
|
||||
}
|
||||
|
||||
+23
-4
@@ -1,7 +1,10 @@
|
||||
//! Owner-managed asynchronous work. Only weak identities enter the scheduler;
|
||||
//! callbacks and scopes are ordinary traced edges in the Aster object graph.
|
||||
use std::{
|
||||
sync::{Arc, Mutex},
|
||||
sync::{
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
@@ -215,6 +218,7 @@ struct After {
|
||||
provider: crate::io_tasks::Provider,
|
||||
signature: endor_core::CallSignature,
|
||||
index: Index,
|
||||
runnable: Arc<AtomicBool>,
|
||||
desktop: ObjectRef,
|
||||
}
|
||||
impl NativeCallable for After {
|
||||
@@ -407,6 +411,9 @@ impl NativeCallable for After {
|
||||
live.retain(|old| Some(*old) != previous_weak);
|
||||
live.push(weak);
|
||||
*index = live;
|
||||
if self.operation == Operation::Spawn {
|
||||
self.runnable.store(true, Ordering::Release);
|
||||
}
|
||||
Ok(NativeResult::Return(Value::Object(task)))
|
||||
}
|
||||
}
|
||||
@@ -512,10 +519,14 @@ impl NativeCallable for Method {
|
||||
|
||||
pub struct Scheduler {
|
||||
index: Index,
|
||||
runnable: Arc<AtomicBool>,
|
||||
desktop: ObjectRef,
|
||||
provider: crate::io_tasks::Provider,
|
||||
}
|
||||
impl Scheduler {
|
||||
pub fn has_cooperative_work(&self) -> bool {
|
||||
self.runnable.load(Ordering::Acquire)
|
||||
}
|
||||
/// Mutation boundaries collect unreachable owner/callback cycles before
|
||||
/// this weak lookup. Idle timer polling does not rescan the entire heap.
|
||||
pub fn poll(&self, vm: &mut Vm, limit: usize) -> Result<usize> {
|
||||
@@ -679,6 +690,7 @@ impl Scheduler {
|
||||
.map_err(|_| anyhow::anyhow!("task index poisoned"))?;
|
||||
let count = index.len();
|
||||
index.clear();
|
||||
self.runnable.store(false, Ordering::Release);
|
||||
Ok(count)
|
||||
}
|
||||
fn prune(&self, vm: &mut Vm) -> Result<()> {
|
||||
@@ -687,11 +699,14 @@ impl Scheduler {
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("task index poisoned"))?;
|
||||
let mut live = Vec::new();
|
||||
let mut runnable = false;
|
||||
for weak in index.iter().copied() {
|
||||
if let Some(task) = vm.upgrade(weak)? {
|
||||
let pending = vm
|
||||
.payload::<Task>(task, "Task")
|
||||
.map(|task| matches!(task.state, State::Pending | State::Running));
|
||||
let pending = vm.payload::<Task>(task, "Task").map(|task| {
|
||||
let pending = matches!(task.state, State::Pending | State::Running);
|
||||
runnable |= pending && task.cooperative;
|
||||
pending
|
||||
});
|
||||
vm.release(task)?;
|
||||
if pending? {
|
||||
live.push(weak);
|
||||
@@ -699,6 +714,7 @@ impl Scheduler {
|
||||
}
|
||||
}
|
||||
*index = live;
|
||||
self.runnable.store(runnable, Ordering::Release);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -815,6 +831,7 @@ pub fn install(
|
||||
desktop: ObjectRef,
|
||||
) -> Result<Scheduler> {
|
||||
let index = Arc::new(Mutex::new(Vec::new()));
|
||||
let runnable = Arc::new(AtomicBool::new(false));
|
||||
let definition = desktop_type(vm.object_store(), "Task", desktop)?;
|
||||
let provider = crate::io_tasks::Provider::default();
|
||||
for (name, operation) in [
|
||||
@@ -858,6 +875,7 @@ pub fn install(
|
||||
signature
|
||||
},
|
||||
index: index.clone(),
|
||||
runnable: runnable.clone(),
|
||||
desktop,
|
||||
},
|
||||
vec![desktop],
|
||||
@@ -898,6 +916,7 @@ pub fn install(
|
||||
}
|
||||
Ok(Scheduler {
|
||||
index,
|
||||
runnable,
|
||||
desktop,
|
||||
provider,
|
||||
})
|
||||
|
||||
@@ -1812,6 +1812,10 @@ fn project_tabs(
|
||||
}
|
||||
|
||||
impl UiBridge {
|
||||
pub fn has_cooperative_tasks(&self) -> bool {
|
||||
self.tasks.has_cooperative_work()
|
||||
}
|
||||
|
||||
pub fn poll_tasks(&self, vm: &mut Vm, limit: usize) -> Result<usize> {
|
||||
self.tasks.poll(vm, limit)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user