DEV Community

Discussion on: Async / Await: From Zero to Hero

Collapse
 
zhiyuanamos profile image
Zhi Yuan • Edited

Hey there, appreciate your helpful insights concerning ConfigureAwait(false). :)

async/await introduces more complexity at CIL level and thus costs memory and CPU time. This should be taken into consideration when writing async code.

You are spot-on concerning this. For the benefit of those reading this comment, this SO post gives 2 examples concerning the added complexity at CIL level when using async / await.

When do you decide to use async code?

I'm not sure if I got your question right, but I suppose you are asking this in relation to the added complexity at CIL level. If so, Stephen Cleary's post provides a thorough explanation on this matter, and I'll summarise some of the key points here:

It’s more efficient to elide async and await

Which you have mentioned rightly. However,

it’s important to point out that each of these gains are absolutely minimal... In almost every scenario, eliding async and await doesn’t make any difference to the running time of your application.

I suggest following these guidelines:

  1. Do not elide by default. Use the async and await for natural, easy-to-read code.
  2. Do consider eliding when the method is just a passthrough or overload.

Stephen Cleary also provides examples of pitfalls, one concerning using the using statement, and the other concerning exceptions. He gives an amazing and concise explanation there, so I'll not copy the quotes here.

Thanks for your question! You helped me to dig deeper into this topic, which resulted in me finding Stephen's blog post.

Collapse
 
gabbersepp profile image
Josef Biehler

Thanks for linking that blog posts. I will read through it. Sounds very interesting!