Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
perf(desktop-gpui): hold 1 ms timer resolution during Windows exports (#2439)
Luke Parker2540a73a8c08
diff --git a/apps/desktop-gpui/Cargo.toml b/apps/desktop-gpui/Cargo.tomlindex de7f91841..0a0b78d97 100644--- a/apps/desktop-gpui/Cargo.toml+++ b/apps/desktop-gpui/Cargo.toml@@ -186,6 +186,7 @@ raw-window-handle = "0.6"tray-icon = { version = "0.21.1", default-features = false }windows-sys = { version = "0.59", features = ["Win32_Foundation",+ "Win32_Media","Win32_Security","Win32_System_SystemInformation","Win32_System_Threading",diff --git a/apps/desktop-gpui/src/editor_export.rs b/apps/desktop-gpui/src/editor_export.rsindex 5b3b44f97..6e8457a0a 100644--- a/apps/desktop-gpui/src/editor_export.rs+++ b/apps/desktop-gpui/src/editor_export.rs@@ -2867,6 +2867,26 @@ fn matches_compression(current: ExportCompression, expected: ExportCompression)std::mem::discriminant(¤t) == std::mem::discriminant(&expected)}+// The NV12 readback wait sleeps in 1 ms steps (`frame_pipeline.rs`), which the+// default 15.6 ms Windows timer resolution stretches to most of a frame each.+#[cfg(windows)]+struct TimerResolution;++#[cfg(windows)]+impl TimerResolution {+ fn hold_one_millisecond() -> Self {+ unsafe { windows_sys::Win32::Media::timeBeginPeriod(1) };+ Self+ }+}++#[cfg(windows)]+impl Drop for TimerResolution {+ fn drop(&mut self) {+ unsafe { windows_sys::Win32::Media::timeEndPeriod(1) };+ }+}+#[allow(clippy::too_many_arguments)]async fn run_export(project_path: PathBuf,@@ -2887,6 +2907,8 @@ async fn run_export(if cancel.load(Ordering::Relaxed) {return Err("Export cancelled".into());}+ #[cfg(windows)]+ let _timer_resolution = TimerResolution::hold_one_millisecond();let mut builder = ExporterBase::builder(project_path).with_force_ffmpeg_decoder(force);if cursor_only {