Skip to content

Commit ba71c17

Browse files
Legend-Mastermontyc1999
authored andcommitted
refactor: dynamic dispatch async commands in debug (tauri-apps#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 1c6bc59 commit ba71c17

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
@@ -336,6 +336,34 @@ impl<R: Runtime> InvokeResolver<R> {
336336

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

0 commit comments

Comments
 (0)