Can using async-await give you any performance benefits?

前端 未结 6 1486
滥情空心
滥情空心 2020-12-14 01:41

Whenever I read about async-await, the use case example is always one where there\'s a UI that you don\'t want to freeze. Either a

6条回答
  •  长情又很酷
    2020-12-14 01:57

    Most often you don't gain in direct performance (task you are performing happens faster and/or in less memory) as in scalability; using less threads to perform the same number of simultaneous tasks means the number of simultaneous tasks you can do is higher.

    For the most part therefore, you don't find a given operation improving in performance, but can find heavy use has improved performance.

    If an operation requires parallel tasks that involve something truly async (multiple async I/O) then that scalability can though benefit that single operation. Because the degree of blocking happening in threads is reduced, this happens even if you have only one core, because the machine divides its time only between those tasks that are not currently waiting.

    This differs from parallel CPU-bound operations which (whether done using tasks or otherwise) will generally only scale up to the number of cores available. (Hyper-threaded cores behave like 2 or more cores in some regards and not in others).

提交回复
热议问题