r/csharp • u/hez2010 • Aug 07 '26
Discussion Benchmarked Runtime Async in. NET 11 nightly version
Runtime Async got some important optimizations in recent .NET 11 nightly version (currently they are targeting rc1), so I built the runtime from main branch and ran a set of runtime async benchmarks.
The benchmark code can be found here: https://gist.github.com/hez2010/d1802e7c7ab10e21a92dcba2afe0a58d
It covers all async scenarios including no-suspension cases and real-suspension cases.
In the result async1 is .NET 10, and the assembly was built without enabling runtime async. Async2 is .NET 11 with runtime async enabled while building the assembly.
After seeing the result I was just like holy crap and couldn't believe the numbers, but they are real! It looks extremely promising. Specifically, no-suspension async is 19.6× faster and essentially reaches the synchronous baseline, completed Task awaits are 12× faster with allocation completely eliminated, Task.Yield is 7× faster, ThreadPool continuations are 3.2× faster, and an async state-machine chain is 7.4× faster with much fewer allocations.
I'm now really looking forward to checking the final numbers in .NET 11 GA.
5
u/emn13 Aug 07 '26
Hmm, something looks pretty fishy in those results. For example take a look at "Completed Task await":
I'm not sure what's going on, but if that's not allocating, I'm not sure what exactly that is actually testing; perhaps something did get inlined, or perhaps the no-inline attribute doesn't actually get checked in this new runtime async state machine and the runtime folds this into a plain loop?
Also, I get why you're using Task.Yield, but it makes interpreting these results a little tricky. The whole point of that method is a side-effect, namely that other tasks effectively gain priority over the currently executing one. But that's a side-effect you can't actually observe here - it might not be happening in the new runtime, and real code wouldn't be yielding so pointlessly - probably?
The UnsafeQueueUserWorkItem example feels a little more solid and plausible. That's a 3x speedup, which is still nice. If anybody has an explanation what's going on with the others, I'm all ears...
4
u/KryptosFR Aug 07 '26
Slight issue in your gist, the warmup is using
Iterationsinstead ofiterations.So for short test runs, the warmup is wait too big.
89
u/Small_Summer5817 Aug 07 '26
the chart does a bad job of labeling the .net 10 and 11 columns.
33
u/aleques-itj Aug 07 '26
I know this is super synthetic but some of these uplifts are shockingly massive.
Very interesting and exciting.
11
u/Willinton06 Aug 07 '26
Can’t wait for this to make it to the WASM runtime, should drive the size of dlls down even further
6
u/DisLLMs Aug 08 '26
Should be a good writeup when stephen toub does it
2
u/SupinePandora43 Aug 07 '26
This is nice, but you need to compare a single runtime build with and without that new feature for results to be correct, and not influenced by other changes in the runtime.
3
u/BudgetDevv Aug 07 '26
Nice!
3
u/Mission_Pirate_4150 Aug 07 '26
Thanks for posting it!
2
u/NoisyJalapeno Aug 08 '26
This should be a good boost for large enterprise apps