Skip to content

Commit 6a39f49

Browse files
refactor: dynamic dispatch async commands in debug (#13464)
* Dynamic dispatch async commands * format * Preserve `'static` * Use a inner function instead * Only do it for dev for now * Add change file * Tag respond_async_serialized_dyn with debug
1 parent a35600c commit 6a39f49

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tauri: "patch:perf"
3+
---
4+
5+
Use dynamic dispatch for async commands in dev, this should speed up the compilation time by quite a bit, and significantly reduces the incremental compilation time

crates/tauri/src/ipc/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,34 @@ impl<R: Runtime> InvokeResolver<R> {
339339

340340
/// Reply to the invoke promise with an async task which is already serialized.
341341
pub fn respond_async_serialized<F>(self, task: F)
342+
where
343+
F: Future<Output = Result<InvokeResponseBody, InvokeError>> + Send + 'static,
344+
{
345+
// Dynamic dispatch the call in dev for a faster compile time
346+
// TODO: Revisit this and see if we can do this for the release build as well if the performace hit is not a problem
347+
#[cfg(debug_assertions)]
348+
{
349+
self.respond_async_serialized_dyn(Box::pin(task))
350+
}
351+
#[cfg(not(debug_assertions))]
352+
{
353+
self.respond_async_serialized_inner(task)
354+
}
355+
}
356+
357+
/// Dynamic dispatch the [`Self::respond_async_serialized`] call
358+
#[cfg(debug_assertions)]
359+
fn respond_async_serialized_dyn(
360+
self,
361+
task: std::pin::Pin<
362+
Box<dyn Future<Output = Result<InvokeResponseBody, InvokeError>> + Send + 'static>,
363+
>,
364+
) {
365+
self.respond_async_serialized_inner(task)
366+
}
367+
368+
/// Reply to the invoke promise with an async task which is already serialized.
369+
fn respond_async_serialized_inner<F>(self, task: F)
342370
where
343371
F: Future<Output = Result<InvokeResponseBody, InvokeError>> + Send + 'static,
344372
{

0 commit comments

Comments
 (0)