Investigate possibility of returning Pending after each batch inserted into "holding" streams.
Is your feature request related to a problem or challenge?
In streams like the ExternalSorter stream, and some agg streams, and I'm sure in many others, we only return pending from the await, essentially polling the child stream in a loop until it is consumed, if the child stream comes from a stream which will always yield Ready(such as a parquet reader which already fetched all its data), we will never relinquish control back to the executor. This may be performant in some cases, but will also be obtrusive to actual async behaviour in the future.
Describe the solution you'd like
We should investigate the performance impact of polling the child stream, if it returns Pending, return, if it returns Ready(Some()), insert the batch into the sorter, and return Pending, until the child stream returns Ready(None), then we can actually call the sort function, which will actually provide a stream of batches.
This is just a concrete example for SortExec, but I'm sure there are many operators that do the same. This can prevent thread starvation in a lot of cases, as well as allow more optimal behaviour should we every become fully async.
Describe alternatives you've considered
No response
Additional context
No response
Hi @EmilyMatt,
Thanks for opening this – interesting problem.
I’d like to help investigate this. I’m planning to:
- Explore the current behavior around polling child streams and Pending/Ready semantics
- Check where similar patterns exist (e.g. SortExec and other operators)
- Run some small benchmarks or traces to understand performance and scheduling impact
- Share findings and possible approaches before proposing any code changes
Let me know if this sounds useful or if there’s a preferred direction to explore.