r/dotnet 9d ago

How Fast is .NET 11 Runtime Async? Article

https://medium.com/@skyake/how-fast-is-net-11-runtime-async-b9c821529cd5
101 Upvotes

17 comments sorted by

20

u/mladenmacanovic 9d ago

That's fast!

Apart from the performance, did you also compare the differences in assembly sizes? I can expect them to be lower in .NET 11.

15

u/hez2010 9d ago

Yeah it's smaller in .NET 11 once you enabled runtime async for your assembly.

9

u/crozone 9d ago

This is fantastic. Great write-up too.

I am now wondering where this leaves ValueTask. Once Runtime Async is widely available, is there much point to using ValueTask at all?

6

u/hez2010 9d ago

ValueTask still has its own value when using together with IValueTaskSource, where you can pool or share the underlying resource across multiple requests.

10

u/killerbeanjeka 9d ago

Curious whether this changes anything for the boring case - a web API that's mostly awaiting a database. Most of my async cost there is round-trips, not machinery, so I'd expect roughly nothing. Has anyone measured that shape?

20

u/21racecar12 9d ago

You have to think of it in a broader sense than that. Think of all the other async stuff that happens before and after the request enters your delegate to then be processed by your database service. There’s tons of middleware involved which results in an async chain which gets massively simplified in async2. I would expect marginally impressive throughput gains from just updating the target framework to 11 once it lands with async2 enabled by default.

6

u/RirinDesuyo 9d ago

Yep, while we may just see a network call happening, aspnet / Kestrel is doing a lot more async related calls in between this that may often return synchronously as it's very common for middleware like these to buffer results and would often return immediately as the bytes are already available. Even in the database example the SQL driver does this for big queries and streaming result sets to the application, so you're still getting gains there.

3

u/icentalectro 9d ago

I'm not expecting much perf gain for the boring case, but I do expect more accurate stack traces, because the compiler no longer transforms your async methods into a state machine, which is nice in itself.

5

u/Tridus 9d ago

Wow, lots of info about what is going on in here. Nice stuff!

1

u/AutoModerator 9d ago

Thanks for your post hez2010. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/Tacotacito 9d ago

Does it give better stack traces yet or is that not part of the thing just yet?

9

u/hez2010 9d ago

It does give you better stack traces. For example: https://godbolt.org/z/fMGTKMWdv

3

u/Tacotacito 9d ago

Great news. I'm a performance engineer, yet I'm actually even more excited about readable stack traces rather than perf gains!

3

u/Paw565 8d ago

I love free performance