Description
Let me share a couple of considerations related to Task.WhenAll
performance, specifically for WhenAll<TResult>(IEnumerable<Task<TResult>> tasks)
overload.
-
Currently if
tasks
is notICollection<T>
and therefore the count is not known, it will create a list of tasks and then returnnew WhenAllPromise<TResult>(list.ToArray())
. It seems likeWhenAllPromise
could take aSpan<T>
instead of an array, but currently it cannot because it stores that array into the field. Looks like the field is there only to be used inShouldNotifyDebuggerOfWaitCompletion
property and is probably needed only for debugging, can that allocation made bylist.ToArray()
be avoided in release builds? -
I believe that it's pretty common when a set of tasks is produced for some collection of items, e.g when calling
source.Select(x => ProcessAsync(x))
. We know collection size, but then we're losing it when callingSelect
. It probably would make sense to handleIterator<T>
internal type to get task count if it's available to avoid unnecessary allocations.