-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Let me share a couple of considerations related to Task.WhenAll performance, specifically for WhenAll<TResult>(IEnumerable<Task<TResult>> tasks) overload.
-
Currently if
tasksis 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 likeWhenAllPromisecould 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 inShouldNotifyDebuggerOfWaitCompletionproperty 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.