From 8e3bd63db919a4cf72bb3d28028033d8654deb34 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Thu, 13 Nov 2025 15:24:10 +0800 Subject: [PATCH] perf(codegen): wrap generated context in a fn (#14457) * perf(codegen): wrap generated context in a fn * Add comment about the reasoning --- .changes/wrap-generate-context.md | 5 +++++ crates/tauri-codegen/src/context.rs | 25 +++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 .changes/wrap-generate-context.md diff --git a/.changes/wrap-generate-context.md b/.changes/wrap-generate-context.md new file mode 100644 index 000000000..10f610a39 --- /dev/null +++ b/.changes/wrap-generate-context.md @@ -0,0 +1,5 @@ +--- +"tauri-codegen": "patch:perf" +--- + +Wrap the generated context code in a function to make rust analyzer faster diff --git a/crates/tauri-codegen/src/context.rs b/crates/tauri-codegen/src/context.rs index 87a05d702..b60d2b9fd 100644 --- a/crates/tauri-codegen/src/context.rs +++ b/crates/tauri-codegen/src/context.rs @@ -469,19 +469,24 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult { }); Ok(quote!({ - let thread = ::std::thread::Builder::new() - .name(String::from("generated tauri context creation")) - .stack_size(8 * 1024 * 1024) - .spawn(|| #context) - .expect("unable to create thread with 8MiB stack"); + // Wrapping in a function to make rust analyzer faster, + // see https://github.com/tauri-apps/tauri/pull/14457 + fn inner() -> #root::Context { + let thread = ::std::thread::Builder::new() + .name(String::from("generated tauri context creation")) + .stack_size(8 * 1024 * 1024) + .spawn(|| #context) + .expect("unable to create thread with 8MiB stack"); - match thread.join() { - Ok(context) => context, - Err(_) => { - eprintln!("the generated Tauri `Context` panicked during creation"); - ::std::process::exit(101); + match thread.join() { + Ok(context) => context, + Err(_) => { + eprintln!("the generated Tauri `Context` panicked during creation"); + ::std::process::exit(101); + } } } + inner() })) }