CPU bound vs I/O bound

There are two types of asynchronous operations in .NET.

  • I/O bound
  • CPU bound

For I/O bound async/await syntax should be used. TPL should not be used for this. async methods does not spawns new thread to hand le I/O work asynchronously.

For CPU bound operations TPL should be used (Task.Run). This spawns new thread. Performance testing should be done to check if overhead of new thread and context switching is not greater than actual work to be done.

  • CPU bound should be done in thread pool (Task.Run or Parallel.ForEach)
  • I/O bound should not
  • UI thread should do minimal work (mostly update UI or react to user actions)
  • extensive computations should be done on different thread (CPU bound).
  • I/O waits should be awaited (less overhead since ThreadPool have some overhead)
  • if I/O task are awaited then it is easier to update UI with new data (only one thread is allowed to update UI – main one)

Further read:

https://learn.microsoft.com/en-us/shows/three-essential-tips-for-async/tip-2-distinguish-cpu-bound-work-from-io-bound-work

2 Replies to “CPU bound vs I/O bound”

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve : *
14 + 18 =