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
This commit is contained in:
Tony 2025-05-29 22:02:56 +08:00 committed by GitHub
parent a35600cbd7
commit 6a39f49991
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -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

View File

@ -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,
{