mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-23 03:39:35 -10:00
When supplied with a small number of actions, Parallel.Invoke processes them with one task for each (for more actions it uses a parallel loop). Today, it starts each task and then waits for them all. The act of waiting on them will attempt to inline any that haven't started yet, but if a smaller number of actions is provided than there are free threads in the thread pool, there's a good chance that all of the actions will have started executing by the time we call WaitAll, at which point WaitAll won't be able to inline any of them. Instead, we can queue N-1 of the tasks and run one of them synchronously on the current thread (assuming the associated scheduler allows it, which the default will); this optimization already happens implicitly in the other path the uses a parallel loop. (This change was already made for the full framework.) Commit migrated from https://github.com/dotnet/corefx/commit/fee132f8ece1e69a858f289fe09bb1703b3a56f7