Hacker News new | ask | show | jobs
by 0xcoffee 561 days ago
The C# version will copy the list into an array during Task.WhenAll, it may save some memory to use an array directly.

Souce: https://github.com/microsoft/referencesource/blob/master/msc...

2 comments

The referencesource repository is only relevant if you are using the legacy .NET Framework. Modern .NET has a special case for passing a List<Task> and avoids the allocation:

https://github.com/dotnet/runtime/blob/1f01bee2a41e0df97089f...

It doesn't take that much space, and not all languages have option to easily map an initial range onto an iterator that produces tasks. Most are dominated by the size of state machines/virtual threads.

Please note that the link above leads to old code from .NET Framework.

The up-to-date .NET implementation lives here: https://github.com/dotnet/runtime/blob/main/src/libraries/Sy...