File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
futures-util/src/stream/futures_unordered Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 66use crate :: task:: AtomicWaker ;
77use alloc:: sync:: { Arc , Weak } ;
88use core:: cell:: UnsafeCell ;
9+ use core:: cmp;
910use core:: fmt:: { self , Debug } ;
1011use core:: iter:: FromIterator ;
1112use core:: marker:: PhantomData ;
@@ -393,11 +394,14 @@ impl<Fut: Future> Stream for FuturesUnordered<Fut> {
393394 // caps the number of calls to `poll` on underlying futures a single call to
394395 // `poll_next` is allowed to make.
395396 //
396- // The value is the length of FuturesUnordered. This ensures that each
397- // future is polled only once at most per iteration.
397+ // The value itself is chosen somewhat arbitrarily. It needs to be high enough
398+ // that amortize wakeup and scheduling costs, but low enough that we do not
399+ // starve other tasks for long.
400+ //
401+ // Each future is polled only once *at most* per iteration.
398402 //
399403 // See also https://github.com/rust-lang/futures-rs/issues/2047.
400- let yield_every = self . len ( ) ;
404+ let yield_every = cmp :: min ( self . len ( ) , 32 ) ;
401405
402406 // Keep track of how many child futures we have polled,
403407 // in case we want to forcibly yield.
You can’t perform that action at this time.
0 commit comments