perf(proofing): run proof_text on a blocking thread

proof_text loaded the dictionary and ran spell/grammar checks
synchronously inside an async command, blocking an async-runtime worker
and holding the engine mutex for the whole call. Move the work to
spawn_blocking so IPC stays responsive under load.
This commit is contained in:
pj committed 2026-06-22 12:01:25 -04:00
1 parent 3177b2f1eb
commit 39609fbd09
1 file changed
+6 -2
+6 -2
View File
@@ -176,12 +176,13 @@ fn collect_grammar(harper: &mut Harper, text: &str, chars: &[char], issues: &mut
#[tauri::command] #[tauri::command]
pub async fn proof_text( pub async fn proof_text(
app: tauri::AppHandle, app: tauri::AppHandle,
state: tauri::State<'_, ProofState>,
text: String, text: String,
spelling: bool, spelling: bool,
grammar: bool, grammar: bool,
) -> Result<Vec<Issue>, String> { ) -> Result<Vec<Issue>, String> {
let mut guard = state.inner().lock().map_err(|e| e.to_string())?; tauri::async_runtime::spawn_blocking(move || -> Result<Vec<Issue>, String> {
let state = app.state::<ProofState>();
let mut guard = state.lock().map_err(|e| e.to_string())?;
if guard.is_none() { if guard.is_none() {
*guard = Some(Engine { *guard = Some(Engine {
speller: None, speller: None,
@@ -206,6 +207,9 @@ pub async fn proof_text(
collect_grammar(engine.harper.as_mut().unwrap(), &text, &chars, &mut issues); collect_grammar(engine.harper.as_mut().unwrap(), &text, &chars, &mut issues);
} }
Ok(issues) Ok(issues)
})
.await
.map_err(|e| e.to_string())?
} }
#[tauri::command] #[tauri::command]