Skip to content
5 changes: 5 additions & 0 deletions .changes/dynamic-dispatch-async-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tauri: "patch:perf"
---

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
28 changes: 28 additions & 0 deletions crates/tauri/src/ipc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,34 @@ impl<R: Runtime> InvokeResolver<R> {

/// Reply to the invoke promise with an async task which is already serialized.
pub fn respond_async_serialized<F>(self, task: F)
where
F: Future<Output = Result<InvokeResponseBody, InvokeError>> + Send + 'static,
{
// Dynamic dispatch the call in dev for a faster compile time
// TODO: Revisit this and see if we can do this for the release build as well if the performace hit is not a problem
#[cfg(debug_assertions)]
{
self.respond_async_serialized_dyn(Box::pin(task))
}
#[cfg(not(debug_assertions))]
{
self.respond_async_serialized_inner(task)
}
}

/// Dynamic dispatch the [`Self::respond_async_serialized`] call
#[cfg(debug_assertions)]
fn respond_async_serialized_dyn(
self,
task: std::pin::Pin<
Box<dyn Future<Output = Result<InvokeResponseBody, InvokeError>> + Send + 'static>,
>,
) {
self.respond_async_serialized_inner(task)
}

/// Reply to the invoke promise with an async task which is already serialized.
fn respond_async_serialized_inner<F>(self, task: F)
where
F: Future<Output = Result<InvokeResponseBody, InvokeError>> + Send + 'static,
{
Expand Down
Loading