From be0eb86cd0fdc670b59c085feb30ab618a811c01 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 9 Aug 2026 10:15:23 +0000 Subject: [PATCH] refactor(tauri): parallelize load_extensions via async blocking pool Replaces the synchronous, blocking file-read loop in the `load_extensions` Tauri command with concurrent execution using `tauri::async_runtime::spawn_blocking` and `futures::future::join_all`. This prevents blocking the IPC thread during startup when loading multiple user scripts, significantly improving performance for users with many extensions. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src-tauri/Cargo.lock | 4 ++-- src-tauri/src/main.rs | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 281bbeb..e2133c5 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4376,9 +4376,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.52.3" +version = "1.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" dependencies = [ "bytes", "libc", diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 74c4642..32ca3ab 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -631,18 +631,24 @@ fn extensions_dir(app: &AppHandle) -> PathBuf { } #[tauri::command] -fn load_extensions(app: AppHandle) -> Vec { +async fn load_extensions(app: AppHandle) -> Vec { let mut out = Vec::new(); if let Ok(entries) = fs::read_dir(extensions_dir(&app)) { + let mut tasks = Vec::new(); for entry in entries.flatten() { let path = entry.path(); if path.extension().is_some_and(|e| e == "js") { - if let Ok(code) = fs::read_to_string(&path) { - out.push(ExtensionScript { - name: entry.file_name().to_string_lossy().into_owned(), - code, - }); - } + let name = entry.file_name().to_string_lossy().into_owned(); + tasks.push(tauri::async_runtime::spawn_blocking(move || { + fs::read_to_string(&path) + .ok() + .map(|code| ExtensionScript { name, code }) + })); + } + } + for task in tasks { + if let Ok(Some(script)) = task.await { + out.push(script); } } }