feat: coalesce viewport changes by cancelling unpublished layout work
This commit is contained in:
+22
-4
@@ -229,6 +229,8 @@ struct Session {
|
||||
next_mount: u64,
|
||||
retired_commands: Vec<crate::window::Command>,
|
||||
refresh_yields: usize,
|
||||
refresh_restarts: usize,
|
||||
layout_cancels: usize,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for Session {
|
||||
@@ -1155,6 +1157,8 @@ impl NativeCallable for Function {
|
||||
("layoutPasses", session.layout.settle_passes as i64),
|
||||
("layoutSlices", session.layout.slices as i64),
|
||||
("refreshYields", session.refresh_yields as i64),
|
||||
("refreshRestarts", session.refresh_restarts as i64),
|
||||
("layoutCancels", session.layout_cancels as i64),
|
||||
] {
|
||||
cx.set_attr(stats, name, Value::Number(value.into()))?;
|
||||
}
|
||||
@@ -2611,6 +2615,18 @@ impl UiBridge {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn note_refresh_restart(&self, cancelled_layout: bool) -> Result<()> {
|
||||
let mut state = self
|
||||
.session
|
||||
.lock()
|
||||
.map_err(|_| anyhow::anyhow!("UI session poisoned"))?;
|
||||
state.refresh_restarts = state.refresh_restarts.saturating_add(1);
|
||||
state.layout_cancels = state
|
||||
.layout_cancels
|
||||
.saturating_add(usize::from(cancelled_layout));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn discard_layout_context(&self, vm: &mut Vm, context: LayoutContext) -> Result<()> {
|
||||
let LayoutContext {
|
||||
desktop,
|
||||
@@ -2627,10 +2643,10 @@ impl UiBridge {
|
||||
state.force_frame = true;
|
||||
result.map_err(anyhow::Error::from)
|
||||
}
|
||||
Err(_) => {
|
||||
checkpoint.release(vm)?;
|
||||
Err(anyhow::anyhow!("UI session poisoned"))
|
||||
}
|
||||
Err(_) => checkpoint
|
||||
.release(vm)
|
||||
.map_err(anyhow::Error::from)
|
||||
.and(Err(anyhow::anyhow!("UI session poisoned"))),
|
||||
}
|
||||
} else {
|
||||
checkpoint.release(vm).map_err(anyhow::Error::from)
|
||||
@@ -2809,6 +2825,8 @@ pub fn install(vm: &mut Vm, roots: &mut Vec<ObjectRef>) -> Result<UiBridge> {
|
||||
next_mount: 0,
|
||||
retired_commands: Vec::new(),
|
||||
refresh_yields: 0,
|
||||
refresh_restarts: 0,
|
||||
layout_cancels: 0,
|
||||
}));
|
||||
let mut public_functions = Vec::new();
|
||||
let mut factories = Vec::new();
|
||||
|
||||
Reference in New Issue
Block a user