Great questions, I think the documentation could do with some more detail.
io()
is backed by an unbounded thread-pool and is the sort of thing you’d use for non-computationally intensive tasks, that is stuff that doesn’t put much load on the CPU. So yep interaction with the file system, interaction with databases or services on a different host are good examples.computation()
is backed by a bounded thread-pool with size equal to the number of available processors. If you tried to schedule CPU intensive work in parallel across more than the available processors (say usingnewThread()
) then you are up for thread creation overhead and context switching overhead as threads vie for a processor and it’s potentially a big performance hit.- It’s best to leave
computation()
for CPU intensive work only otherwise you won’t get good CPU utilization. - It’s bad to call
io()
for computational work for the reason discussed in 2.io()
is unbounded and if you schedule a thousand computational tasks onio()
in parallel then each of those thousand tasks will each have their own thread and be competing for CPU incurring context switching costs.