Se7eN
03/22/2021, 4:43 PM<http://Dispatchers.IO|Dispatchers.IO>
or Dispatchers.Default
for drawing with canvas on a bunch of bitmaps (GIF frames)?Big Chungus
03/22/2021, 4:45 PMDispatchers.Main
if you have it or Dispatchers.Default
if you don't. <http://Dispatchers.IO|Dispatchers.IO>
is mainly reserved for blocking operations like reading files or fetching stuff over the network.Se7eN
03/22/2021, 4:49 PMMain
blocks the UI thread so I'd use Default
. Thanks!Big Chungus
03/22/2021, 4:50 PMSe7eN
03/22/2021, 4:53 PMBig Chungus
03/22/2021, 4:54 PMDispatchers.Main
for this.Zach Klippenstein (he/him) [MOD]
03/23/2021, 3:34 AMIO
is for work that blocks the thread, but doesn’t actually do any work on the CPU while blocking – IO calls block but they hand control over to the kernel and then just sit there idle until the kernel gives a result back. Since these threads just hold state but don’t actually use the CPU while blocked, there can be many more active IO threads than CPU cores (i believe the default is 64). The only real limit here is memory and how many IO operations your OS can reasonably execute concurrently.
Default
is for work that actually executes instructions on the CPU. Work dispatched to these threads actually requires a core to run on, so there are only roughly as many threads in the Default
pool as there are cores/processors on a machine.Erik
03/23/2021, 11:03 AM<http://Dispatchers.IO|Dispatchers.IO>
and Dispatchers.Default
share the same thread pool under the hood, so switching context between them can be efficient as stuff can likely run on the same thread or at least in the same pool. I imagine that only if running out of thread pool resources that these dispatchers will start using disjoint sets of threads, or thread pools. Am I (somewhat) right?
So, given your explanation and my (mis)understanding, what's the actual situation?Zach Klippenstein (he/him) [MOD]
03/23/2021, 3:16 PMDefault
dispatcher will only use roughly the number of threads as you have cores/processors, and the IO
dispatcher will be capped at a higher value (64).Erik
03/23/2021, 5:31 PM