Skip to content

Commit 8e3bd63

Browse files
perf(codegen): wrap generated context in a fn (#14457)
* perf(codegen): wrap generated context in a fn * Add comment about the reasoning
1 parent cfe4787 commit 8e3bd63

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

.changes/wrap-generate-context.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-codegen": "patch:perf"
3+
---
4+
5+
Wrap the generated context code in a function to make rust analyzer faster

crates/tauri-codegen/src/context.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -469,19 +469,24 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
469469
});
470470

471471
Ok(quote!({
472-
let thread = ::std::thread::Builder::new()
473-
.name(String::from("generated tauri context creation"))
474-
.stack_size(8 * 1024 * 1024)
475-
.spawn(|| #context)
476-
.expect("unable to create thread with 8MiB stack");
477-
478-
match thread.join() {
479-
Ok(context) => context,
480-
Err(_) => {
481-
eprintln!("the generated Tauri `Context` panicked during creation");
482-
::std::process::exit(101);
472+
// Wrapping in a function to make rust analyzer faster,
473+
// see https://github.com/tauri-apps/tauri/pull/14457
474+
fn inner<R: #root::Runtime>() -> #root::Context<R> {
475+
let thread = ::std::thread::Builder::new()
476+
.name(String::from("generated tauri context creation"))
477+
.stack_size(8 * 1024 * 1024)
478+
.spawn(|| #context)
479+
.expect("unable to create thread with 8MiB stack");
480+
481+
match thread.join() {
482+
Ok(context) => context,
483+
Err(_) => {
484+
eprintln!("the generated Tauri `Context` panicked during creation");
485+
::std::process::exit(101);
486+
}
483487
}
484488
}
489+
inner()
485490
}))
486491
}
487492

0 commit comments

Comments
 (0)