From 3eb7e24ca6cee8017d52b3b5f79f902fbd1f1f8d Mon Sep 17 00:00:00 2001 From: clover caruso Date: Mon, 19 Oct 2026 21:57:55 -0700 Subject: [PATCH] fix(desktop): keep a replay's ticks from piling up behind a slow window While a replay waits for the window to settle it asked for a frame every 16.7 ms whether or not the last was drawn, so a window drawing slower than that, as on a loaded machine, fell further behind with each one, and the mark that ends a settle waited behind them all: under load the first settle of switching_renderers_keeps_the_window_as_it_was took 35 s, 1809 ticks asked for and 1228 drawn. Past a minute the replay gave up on the step and went on, so the tree it was to write was never written, and the test failed reading it (gate 20261019-213712). A tick is now asked for only once the last has been drawn, and a replay that waits out its minute fails, saying so, rather than going on without what the step was to write. Assisted-by: claude-opus-5.5 --- crates/snowbound/src/main.rs | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/crates/snowbound/src/main.rs b/crates/snowbound/src/main.rs index c6e08f93776fadc3161769708fb56a262f2ed56d..d6bbeb052a5edabe50c825b301a233647b221124 100644 --- a/crates/snowbound/src/main.rs +++ b/crates/snowbound/src/main.rs @@ -417,7 +417,8 @@ enum Replay { /// Waits for nothing to be on its way, then writes the window's accessibility tree as /// text where given, and answers. Settle(Option, std::sync::mpsc::Sender<()>), - /// A frame during a wait, as a visible window's display would ask for. + /// A frame during a wait, as a visible window's display would ask for; one at a time + /// (`TICKING`), so a window drawing slower than the display falls no further behind. Tick, /// What the window sent itself when it found nothing on its way, at that instant: once it /// arrives, so has every event sent before. @@ -6645,6 +6646,9 @@ fn page_text(editor: &CanvasEditor) -> String { /// Work [`spawn`] started that has not ended. static RUNNING: AtomicUsize = AtomicUsize::new(0); +/// A replay's tick is on its way and not yet drawn. +static TICKING: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); + fn spawn(work: impl FnOnce() + Send + 'static) { RUNNING.fetch_add(1, Ordering::Relaxed); let work = move || { @@ -6801,7 +6805,8 @@ impl State { Replay::Settle(path, settled) => { self.replay_settle = Some((path, settled, None)); } - Replay::Tick | Replay::Mark(_) | Replay::Quit => {} + Replay::Tick => TICKING.store(false, Ordering::Release), + Replay::Mark(_) | Replay::Quit => {} Replay::Appearance(appearance) => { self.window.set_theme(Some(appearance)); self.set_appearance(appearance); @@ -6972,6 +6977,7 @@ impl ApplicationHandler for App { UserEvent::Quit => self.close(event_loop), // A cold launch's documents arrive before the window opens. UserEvent::Open(paths) => self.opening.extend(paths), + UserEvent::Replay(Replay::Tick) => TICKING.store(false, Ordering::Release), _ => {} } return; @@ -7244,6 +7250,16 @@ fn write_png(path: &Path, size: [u32; 2], pixels: &[u8]) -> Result<(), Box) { + if !TICKING.swap(true, Ordering::AcqRel) + && proxy.send_event(UserEvent::Replay(Replay::Tick)).is_err() + { + TICKING.store(false, Ordering::Release); + } +} + /// Feeds a development script to the window from another thread, one command per line /// in logical pixels: `move X Y`, `press [right]`, `release [right]`, `wheel DX DY`, /// `pressure LEVEL|none`, `pinch FACTOR`, `key NAME`, `type TEXT`, `modifiers [shift] @@ -7388,15 +7404,20 @@ fn replay(script: String, proxy: EventLoopProxy) -> Result<(), Box= 60 { + eprintln!("The replay never settled"); + std::process::exit(1); + } + tick(&proxy); } } Err(duration) => { @@ -7409,7 +7430,7 @@ fn replay(script: String, proxy: EventLoopProxy) -> Result<(), Box