task: allocate callback on heap immediately in debug mode (#4203)

This commit is contained in:
sander2
2021-10-29 17:34:25 +02:00
committed by GitHub
parent 75c07770bf
commit 44a1aad8df
+5 -1
View File
@@ -193,7 +193,11 @@ impl Handle {
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
self.spawn_blocking_inner(func, None)
if cfg!(debug_assertions) && std::mem::size_of::<F>() > 2048 {
self.spawn_blocking_inner(Box::new(func), None)
} else {
self.spawn_blocking_inner(func, None)
}
}
#[cfg_attr(tokio_track_caller, track_caller)]