From 44a1aad8df43bef416ac91dfc4b9b5614c3d34fd Mon Sep 17 00:00:00 2001 From: sander2 Date: Fri, 29 Oct 2021 17:34:25 +0200 Subject: [PATCH] task: allocate callback on heap immediately in debug mode (#4203) --- tokio/src/runtime/handle.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tokio/src/runtime/handle.rs b/tokio/src/runtime/handle.rs index 3fa012eb0e8..dbd7f47ebee 100644 --- a/tokio/src/runtime/handle.rs +++ b/tokio/src/runtime/handle.rs @@ -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::() > 2048 { + self.spawn_blocking_inner(Box::new(func), None) + } else { + self.spawn_blocking_inner(func, None) + } } #[cfg_attr(tokio_track_caller, track_caller)]