Skip to content

Commit

Permalink
task: allocate callback on heap immediately in debug mode (#4203)
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 committed Oct 29, 2021
1 parent 75c0777 commit 44a1aad
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tokio/src/runtime/handle.rs
Expand Up @@ -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)]
Expand Down

0 comments on commit 44a1aad

Please sign in to comment.