Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
perf(desktop-gpui): warm fonts, the shared device and the renderer after launch so the first editor open shows its frame immediately
Richie McIlroy05dd94977d50
diff --git a/apps/desktop-gpui/src/app_windows.rs b/apps/desktop-gpui/src/app_windows.rsindex 61619c069..107d9f438 100644--- a/apps/desktop-gpui/src/app_windows.rs+++ b/apps/desktop-gpui/src/app_windows.rs@@ -4866,13 +4866,64 @@ pub(crate) async fn shared_wgpu_device() -> Option<cap_rendering::SharedWgpuDevi}}+/// Set once anything has asked for the shared device -- an editor, a+/// screenshot editor or a recording -- so the launch warmup leaves the GPU to+/// it instead of compiling pipelines alongside.+static GPU_WORK_REQUESTED: std::sync::atomic::AtomicBool =+ std::sync::atomic::AtomicBool::new(false);+pub(crate) fn prewarm_shared_wgpu_device(cx: &App) {+ GPU_WORK_REQUESTED.store(true, std::sync::atomic::Ordering::Release);gpui_tokio::Tokio::spawn(cx, async {let _ = shared_wgpu_device().await;}).detach();}+const LAUNCH_RENDER_WARMUP_DELAY: std::time::Duration = std::time::Duration::from_secs(3);++/// The first editor open in a process paid for the system font scan, the+/// shared device and the renderer's first pipeline compiles before its first+/// frame: 0.7-1.2 s, against ~0.2 s for every later open. This warms all three+/// a few seconds after launch, off the main thread. The layers are dropped+/// again; only the driver's compiled pipelines and the font database stay.+pub(crate) fn schedule_launch_render_warmup(cx: &App) {+ gpui_tokio::Tokio::spawn(cx, async {+ tokio::time::sleep(LAUNCH_RENDER_WARMUP_DELAY).await;+ let started = std::time::Instant::now();+ if tokio::task::spawn_blocking(cap_rendering::prewarm_fonts)+ .await+ .is_err()+ {+ return;+ }+ let fonts_ms = started.elapsed().as_secs_f64() * 1000.0;+ let renderer_ms = warm_renderer().await;+ tracing::info!(fonts_ms, ?renderer_ms, "launch render warmup finished");+ })+ .detach();+}++#[cfg(target_os = "macos")]+async fn warm_renderer() -> Option<f64> {+ if GPU_WORK_REQUESTED.load(std::sync::atomic::Ordering::Acquire) {+ return None;+ }+ let shared = shared_wgpu_device().await?;+ let started = std::time::Instant::now();+ tokio::task::spawn_blocking(move || {+ cap_rendering::prewarm_renderer(&shared.device, &shared.queue, shared.is_software_adapter)+ })+ .await+ .ok()?;+ Some(started.elapsed().as_secs_f64() * 1000.0)+}++#[cfg(not(target_os = "macos"))]+async fn warm_renderer() -> Option<f64> {+ None+}+fn editor_audio_output() -> Arc<cap_editor::AudioOutput> {if std::env::var("CAP_GPUI_MUTE_AUDIO").is_ok_and(|value| value == "1") {Arc::new(cap_editor::AudioOutput::new_headless(Box::new(|_, _| {})))diff --git a/apps/desktop-gpui/src/main.rs b/apps/desktop-gpui/src/main.rsindex 10cdb7b09..452df5554 100644--- a/apps/desktop-gpui/src/main.rs+++ b/apps/desktop-gpui/src/main.rs@@ -435,6 +435,7 @@ fn main() {#[cfg(target_os = "linux")]single_instance::init_linux_reopen(cx);updates::schedule_startup_check(cx);+ app_windows::schedule_launch_render_warmup(cx);upload::queue::init(cx);// The app menu (and with it ⌘W/⌘M/⌘Q) and the status-bar item. Both