Skip to content

Commit ee0d096

Browse files
committed
always send large futures to heap
1 parent 12b2567 commit ee0d096

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

tokio/src/runtime/blocking/pool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl Spawner {
300300
R: Send + 'static,
301301
{
302302
let (join_handle, spawn_result) =
303-
if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
303+
if std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
304304
self.spawn_blocking_inner(Box::new(func), Mandatory::NonMandatory, None, rt)
305305
} else {
306306
self.spawn_blocking_inner(func, Mandatory::NonMandatory, None, rt)
@@ -327,7 +327,7 @@ impl Spawner {
327327
F: FnOnce() -> R + Send + 'static,
328328
R: Send + 'static,
329329
{
330-
let (join_handle, spawn_result) = if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
330+
let (join_handle, spawn_result) = if std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
331331
self.spawn_blocking_inner(
332332
Box::new(func),
333333
Mandatory::Mandatory,

tokio/src/runtime/handle.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl Handle {
189189
F: Future + Send + 'static,
190190
F::Output: Send + 'static,
191191
{
192-
if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
192+
if std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
193193
self.spawn_named(Box::pin(future), None)
194194
} else {
195195
self.spawn_named(future, None)
@@ -296,7 +296,7 @@ impl Handle {
296296
/// [`tokio::time`]: crate::time
297297
#[track_caller]
298298
pub fn block_on<F: Future>(&self, future: F) -> F::Output {
299-
if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
299+
if std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
300300
self.block_on_inner(Box::pin(future))
301301
} else {
302302
self.block_on_inner(future)

tokio/src/runtime/runtime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl Runtime {
241241
F: Future + Send + 'static,
242242
F::Output: Send + 'static,
243243
{
244-
if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
244+
if std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
245245
self.handle.spawn_named(Box::pin(future), None)
246246
} else {
247247
self.handle.spawn_named(future, None)
@@ -329,7 +329,7 @@ impl Runtime {
329329
/// [handle]: fn@Handle::block_on
330330
#[track_caller]
331331
pub fn block_on<F: Future>(&self, future: F) -> F::Output {
332-
if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
332+
if std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
333333
self.block_on_inner(Box::pin(future))
334334
} else {
335335
self.block_on_inner(future)

tokio/src/task/builder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'a> Builder<'a> {
8989
Fut::Output: Send + 'static,
9090
{
9191
Ok(
92-
if cfg!(debug_assertions) && std::mem::size_of::<Fut>() > BOX_FUTURE_THRESHOLD {
92+
if std::mem::size_of::<Fut>() > BOX_FUTURE_THRESHOLD {
9393
super::spawn::spawn_inner(Box::pin(future), self.name)
9494
} else {
9595
super::spawn::spawn_inner(future, self.name)
@@ -111,7 +111,7 @@ impl<'a> Builder<'a> {
111111
Fut::Output: Send + 'static,
112112
{
113113
Ok(
114-
if cfg!(debug_assertions) && std::mem::size_of::<Fut>() > BOX_FUTURE_THRESHOLD {
114+
if std::mem::size_of::<Fut>() > BOX_FUTURE_THRESHOLD {
115115
handle.spawn_named(Box::pin(future), self.name)
116116
} else {
117117
handle.spawn_named(future, self.name)
@@ -140,7 +140,7 @@ impl<'a> Builder<'a> {
140140
Fut::Output: 'static,
141141
{
142142
Ok(
143-
if cfg!(debug_assertions) && std::mem::size_of::<Fut>() > BOX_FUTURE_THRESHOLD {
143+
if std::mem::size_of::<Fut>() > BOX_FUTURE_THRESHOLD {
144144
super::local::spawn_local_inner(Box::pin(future), self.name)
145145
} else {
146146
super::local::spawn_local_inner(future, self.name)
@@ -207,7 +207,7 @@ impl<'a> Builder<'a> {
207207
{
208208
use crate::runtime::Mandatory;
209209
let (join_handle, spawn_result) =
210-
if cfg!(debug_assertions) && std::mem::size_of::<Function>() > BOX_FUTURE_THRESHOLD {
210+
if std::mem::size_of::<Function>() > BOX_FUTURE_THRESHOLD {
211211
handle.inner.blocking_spawner().spawn_blocking_inner(
212212
Box::new(function),
213213
Mandatory::NonMandatory,

tokio/src/task/local.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ cfg_rt! {
367367
F: Future + 'static,
368368
F::Output: 'static,
369369
{
370-
if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
370+
if std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
371371
spawn_local_inner(Box::pin(future), None)
372372
} else {
373373
spawn_local_inner(future, None)
@@ -649,7 +649,7 @@ impl LocalSet {
649649
F: Future + 'static,
650650
F::Output: 'static,
651651
{
652-
if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
652+
if std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
653653
self.spawn_named_inner(Box::pin(future), name)
654654
} else {
655655
self.spawn_named_inner(future, name)

tokio/src/task/spawn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ cfg_rt! {
169169
{
170170
// preventing stack overflows on debug mode, by quickly sending the
171171
// task to the heap.
172-
if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
172+
if std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
173173
spawn_inner(Box::pin(future), None)
174174
} else {
175175
spawn_inner(future, None)

0 commit comments

Comments
 (0)